更改Datagridview行颜色 [英] Changing Datagridview Row Color
问题描述
您好,
我有 一个用C#.Net开发的Windows窗体应用程序。它包含数据网格视图。
I have an windows form application developed in C#.Net. It contains a datagridview.
我可以选择配置更改Datagrid中单个选定行的背景颜色,字体,前景颜色等(目前我们禁用了多选属性)。我使用DefaultCellStyle.SelectionBackColor和DefaultCellStyle.SelectionForeColor
来更改所选行的颜色。
I have an option to configure to change background color, font, fore ground color etc. for an single selected row in the Datagrid(currently we disabled multiselect property). I am using DefaultCellStyle.SelectionBackColor and DefaultCellStyle.SelectionForeColor to change the color of selected row.
我们在这里得到了一个新的要求,我想以这样一种方式启用多选属性,不同的选定行应该用不同的颜色,字体等突出显示。
We got a new requirement in this, I would like to enable multi select property in such a way that different selected rows should highlight with different color, font etc.
例如:我会喜欢用不同的颜色和字体突出显示第1行和第5行。在这种情况下,我该如何完成这项任务。
Eg: I would like to highlight Row 1 and Row 5 with different color and font. In this case how can I accomplish this task.
提前致谢
Santosh Kumar Potnuru
Santosh Kumar Potnuru
推荐答案
嗨Santosh,
Hi Santosh,
试试这个:
private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
}
问候,
Frankie
这篇关于更改Datagridview行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!