更改列指定的datagridview颜色 [英] Change the datagridview color specified with column
本文介绍了更改列指定的datagridview颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 winform
C#
datagirdview
和我想在 datagridview
中更改特定行的颜色。当 columncell
的值为false时,应将该行更改为红色。
I am working on winform
C#
datagirdview
and I would like to change the color of a particular row in my datagridview
. The row should be changed to red when the value of columncell
is false.
推荐答案
使用单元格格式化事件
private void dataGridView2_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 1)
{
if (e.Value != null)
{
if ((bool)e.Value)
dataGridView2.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Blue;
else
dataGridView2.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
}
}
编辑:
e.value
的 value 基于 e.ColumnIndex
了解更多详细信息
这篇关于更改列指定的datagridview颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文