c# winform datagrid显示处理问题? 在sql里面写case flag when '0' then '新客户' when '1' then '老客户' end as 客户标识 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DataGridTableStyle dg = new DataGridTableStyle(); dg.MappingName = ds.Tables[0].TableName; dg.GridLineStyle = DataGridLineStyle.Solid; this.dataGrid1.TableStyles.Clear(); dg.GridColumnStyles.Add(new DataGridTextBoxColumn()); dg.GridColumnStyles[0].HeaderText = "序号"; dg.GridColumnStyles[0].Width = 40; dg.GridColumnStyles[0].MappingName = "PrimaryKey"; dg.GridColumnStyles.Add(new DataGridTextBoxColumn()); dg.GridColumnStyles[1].HeaderText = "帐子ID"; dg.GridColumnStyles[1].Width = 60; dg.GridColumnStyles[1].MappingName = "TopicId";2.用sql关联做. 在sql中处理可以,我的问题在于数据源不是从数据库中查出来的,而是从xml中读取的。 xml可转换成datatable,如果你直接绑定的xml的话可在绑定的时候就处理. 我是把xml转成dataset,然后datagrid绑定。如果在xml中处理应该要很麻烦的 在前台处理dgv.columns[0].headtext="序号";dgv.columns[1].headtext="客户"; dgv.columns[2].headtext="客户标识";循环第三列的行:判断是0,1就相应赋值for(int i=0;i<dgv.rows.count;i++){if(dgv.rows[i].cells[2].value.tostring()==0){dgv.rows[i].cells[2].value="新客户";}if(dgv.rows[i].cells[2].value.tostring()==1){dgv.rows[i].cells[2].value="老客户";}} 回7楼:这个是datagridview的处理办法,datagird中没有.rows[i].cells[j].value这个属性。 datagrid里用dropdownlist显示下拉框。private DataGridColorTextColumn dgID; this.dgID = new DataGridColorTextColumn(); dgID.Format =""; dgID.HeaderText =""; dgID.MappingName =""; dgID.Width =75; this.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {this.dgID}); DataGridTableStyle ts1 = new DataGridTableStyle();ts1.MappingName = "";DataGridTextBoxColumn myDataCol1 = new DataGridTextBoxColumn();myDataCol1.HeaderText = ID";myDataCol1.MappingName = "ID";ts1.GridColumnStyles.Add(myDataCol1);dataGrid1.TableStyles.Add(ts1);遍历xml获取属性值到List<T>再绑定到datagiod dataGridView1.Columns["id"].HeaderText = "序号"; dataGridView1.Columns["coustomer"].HeaderText = "客户"; dataGridView1.Columns["flag"].HeaderText = "客户标识"; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells["flag"].Value == "0") dataGridView1.Rows[i].Cells["flag"].Value = "新客户"; else if (dataGridView1.Rows[i].Cells["flag"].Value == "1") dataGridView1.Rows[i].Cells["flag"].Value = "老客户"; } .net 和界面互动的伪Ajax方法 请问MessageBox.Show的返回值 请问有没有开源的OCR可以用? 异步处理问题。。。。 ASP.net 殺掉Excel進程(經典問題) 关于自动发送淘宝旺旺消息... 怎么在一个字符串里面把特定的字符串提取出来? 好,想用C#做一个RSS1.0的阅读器的客户端应用程序, 可行否? 这段代码中的ToString()是哪里来的? 关于DataGrid的索引超出范围的问题 VS2005调试问题,可以在第一个断点处断,但F10后程序跳出 请教????????????
dg.MappingName = ds.Tables[0].TableName;
dg.GridLineStyle = DataGridLineStyle.Solid;
this.dataGrid1.TableStyles.Clear();
dg.GridColumnStyles.Add(new DataGridTextBoxColumn());
dg.GridColumnStyles[0].HeaderText = "序号";
dg.GridColumnStyles[0].Width = 40;
dg.GridColumnStyles[0].MappingName = "PrimaryKey"; dg.GridColumnStyles.Add(new DataGridTextBoxColumn());
dg.GridColumnStyles[1].HeaderText = "帐子ID";
dg.GridColumnStyles[1].Width = 60;
dg.GridColumnStyles[1].MappingName = "TopicId";2.用sql关联做.
如果在xml中处理应该要很麻烦的
dgv.columns[1].headtext="客户";
dgv.columns[2].headtext="客户标识";循环第三列的行:判断是0,1就相应赋值
for(int i=0;i<dgv.rows.count;i++)
{
if(dgv.rows[i].cells[2].value.tostring()==0)
{
dgv.rows[i].cells[2].value="新客户";
}
if(dgv.rows[i].cells[2].value.tostring()==1)
{
dgv.rows[i].cells[2].value="老客户";
}
}
private DataGridColorTextColumn dgID; this.dgID = new DataGridColorTextColumn(); dgID.Format ="";
dgID.HeaderText ="";
dgID.MappingName ="";
dgID.Width =75;
this.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] {this.dgID});
ts1.MappingName = "";DataGridTextBoxColumn myDataCol1 = new DataGridTextBoxColumn();
myDataCol1.HeaderText = ID";
myDataCol1.MappingName = "ID";ts1.GridColumnStyles.Add(myDataCol1);
dataGrid1.TableStyles.Add(ts1);
遍历xml获取属性值到List<T>再绑定到datagiod
dataGridView1.Columns["coustomer"].HeaderText = "客户";
dataGridView1.Columns["flag"].HeaderText = "客户标识";
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells["flag"].Value == "0")
dataGridView1.Rows[i].Cells["flag"].Value = "新客户";
else if (dataGridView1.Rows[i].Cells["flag"].Value == "1")
dataGridView1.Rows[i].Cells["flag"].Value = "老客户";
}