试试 datagridview的 rowsAdded事件的 private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) { string type = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); string value = ""; switch (type) { case "0": value = "数据完整"; break; case "1": value = "已修改"; break; case "2": value = "已注销"; break; default: break; } dataGridView1.Rows[e.RowIndex].Cells[0].Value = value; }
2楼的方法不行啊,提示类型错误。该列数据在数据库里是btye类型的。
很简单,你看能不能sql查询的时候就给他处理了例如:select case 数据列 when 1 then '数据完整' when 2 then '数据以修改' else '已注销' end as 列名 form 表。。如果在sql中做不到处理的话,只能在前台的gridview绑定后循环处理了。 for(int i=0;i<this.datagirdview1.rows.count;i++) { if(this.datagirdview1.rows[i].cells["gird列的名字"].value.tostring.trim()=="1") { this.datagirdview1.rows[i].celss["grid列的名字"].value="数据完整"; } if(和上面的方式相同的处理) if() }
datagridview的
rowsAdded事件的
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
string type = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
string value = "";
switch (type)
{
case "0":
value = "数据完整";
break;
case "1":
value = "已修改";
break;
case "2":
value = "已注销";
break;
default:
break;
}
dataGridView1.Rows[e.RowIndex].Cells[0].Value = value;
}
for(int i=0;i<this.datagirdview1.rows.count;i++)
{
if(this.datagirdview1.rows[i].cells["gird列的名字"].value.tostring.trim()=="1")
{
this.datagirdview1.rows[i].celss["grid列的名字"].value="数据完整";
}
if(和上面的方式相同的处理)
if()
}