DataGridView指定行颜色 显然我可以循环一次,对我需要的行设置颜色,没搜索到合适方法。我希望能有一种方法,我设置一个委托。每次添加行的时候,自动的检查是否符合条件,我就可以只设置条件了。说的明白一点,有一列,表示时间,我希望所有的周日能淡蓝色显示。除了我要自己循环来实现,有没有DataGridView的事件可以更好的实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CellFormatting事件可以private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { //周日的条件判断 e.CellStyle.BackColor = Color.LightBlue; } 在CellFormatting事件中处理 private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (dataGridView1.Rows[e.RowIndex].Cells[0].Value == 1) { } else { } } 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() == "1002" ) { 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); } 正规表达式~!!球一问 请问E-R图的0:n是什么意思? C#对象赋值的问题 winform,登录界面 双击VS2005快捷方式,怎么变成打开Microsoft CLR调试器了? 请教高手:如何在椭圆中画图片? DotNet调用Dll之前如何判断该dll是托管或非托管 Datagrid问题 请教:如何关联 窗体 的退出按钮和 菜单 的退出项?(关闭窗口时,触发菜单的退出按钮,但是点击菜单,会弹出2次确认对话框?) c#调用c++ dll,开发电脑运行正常,其他电脑提示"找不到webcamlib.dll文件 文件拖放时候鼠标跟随的图标 C#代码中途中断一会
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
//周日的条件判断
e.CellStyle.BackColor = Color.LightBlue;
}
{
if (dataGridView1.Rows[e.RowIndex].Cells[0].Value == 1)
{
}
else
{
}
}
{
if (e.RowIndex == -1)
return; DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
try
{
if(e.ColumnIndex==0)
{
if (dgr.Cells["txtID"].Value.ToString() == "1002" )
{
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);
}