如何根据datagridview单元格的内容变动设置其单元格的颜色? 如何根据datagridview单元格的内容变动设置其单元格的颜色? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.Value != null && e.Value.ToString() == "1") { e.CellStyle.BackColor = Color.Red; } } private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex == -1) return; DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex]; try { if(e.ColumnIndex==0) { if (dgr.Cells["txtID"].Value.ToString() == "" ) { e.CellStyle.BackColor = Color.Red; } } if (e.ColumnIndex == 1) { if (dgr.Cells["txtName"].Value.ToString() == "") { e.CellStyle.ForeColor = Color.Red; e.CellStyle.BackColor = Color.Green; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } 如何生成包含"%2F"字符串的uri vs2008 保存时如果做到自动删除末尾空格 急急急,Oracle子查询查不出来不起 网页在本机上好用,传到网上空间里就报错 求问能否让鼠标一段时间内无法移动 怎样检查某一服务器是否存在? 请教各位大大。 如何才能删除数据库表中的一列? (winform) P2P问题 VS.NET编译的问题! Select...Case 语句求教 SerialPort + BeginInvoke实现串通信的多线程问题,高手请帮忙
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.Value != null && e.Value.ToString() == "1")
{
e.CellStyle.BackColor = Color.Red;
}
}
{
if (e.RowIndex == -1)
return; DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
try
{
if(e.ColumnIndex==0)
{
if (dgr.Cells["txtID"].Value.ToString() == "" )
{
e.CellStyle.BackColor = Color.Red;
}
} if (e.ColumnIndex == 1)
{
if (dgr.Cells["txtName"].Value.ToString() == "")
{
e.CellStyle.ForeColor = Color.Red;
e.CellStyle.BackColor = Color.Green;
}
} }
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}