winform中改变DataGridView中符合条件的字体的颜色和列的颜色 .
2013-11-09 07:52
344 查看
/article/9938422.html
只需要使用DataGridView的CellPainting事件。代码如下:
private void dgvUsers_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex < 0)
return;
DataGridViewRow dgr = dgvUsers.Rows[e.RowIndex];
try
{
if (e.ColumnIndex == 3)//定位到第3列,如不定位到具体的哪列,则整行的颜色改变
{
if (dgr.Cells["Column4"].Value.ToString() == "停用")//dgr.Cells["Column4"]为需要判断的列Name,而不是HeadText
{
e.CellStyle.ForeColor = Color.Red;//将前景色设置为红色,即字体颜色设置为红色
e.CellStyle.BackColor = Color.Green;//将背景色设置为绿色,即列的颜色设置为红色
}
}
}
catch
{
}
}
效果图:
只需要使用DataGridView的CellPainting事件。代码如下:
private void dgvUsers_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex < 0)
return;
DataGridViewRow dgr = dgvUsers.Rows[e.RowIndex];
try
{
if (e.ColumnIndex == 3)//定位到第3列,如不定位到具体的哪列,则整行的颜色改变
{
if (dgr.Cells["Column4"].Value.ToString() == "停用")//dgr.Cells["Column4"]为需要判断的列Name,而不是HeadText
{
e.CellStyle.ForeColor = Color.Red;//将前景色设置为红色,即字体颜色设置为红色
e.CellStyle.BackColor = Color.Green;//将背景色设置为绿色,即列的颜色设置为红色
}
}
}
catch
{
}
}
效果图:
相关文章推荐
- SqlServer中计算列详解和winform中改变DataGridView中符合条件的字体的颜色和列的颜色
- [唐胡璐] - winform中改变DataGridView中符合条件的字体的颜色
- winform中改变DataGridView中符合条件的字体的颜色和列的颜色
- [唐胡璐] - winform中改变DataGridView中符合条件的字体的颜色
- 在DataGrid(WinForm)中改变符合指定条件的行颜色的方法
- 在DataGrid(WinForm)中改变符合指定条件的行颜色的方法
- 在DataGrid(WinForm)中改变符合指定条件的行颜色的方法
- 在DataGrid(WinForm)中改变符合指定条件的行颜色的方法
- 在DataGrid(WinForm)中改变符合指定条件的行颜色的方法(转)
- 在DataGrid(WinForm)中改变符合指定条件的行颜色的方法
- [转载]winform中改变DataGridview的列标题字体颜色
- 在DataGrid(WinForm)中改变符合指定条件的行颜色的方法
- 在DataGrid(WinForm)中改变符合指定条件的行颜色的方法
- 在DataGrid(WinForm)中改变符合指定条件的行颜色的方法
- c#改变winform窗体 标题的字体大小 背景 和颜色
- ExtJS GridPanel 根据条件改变字体颜色
- 【WinForm】改变DataGridView的按钮的文字颜色
- dev grdicontrol 根据条件改变行颜色,字体颜色等
- winform 中改变DataGridView中的字体
- WinForm开发中针对TreeView控件改变当前选择节点的字体与颜色