着色Datagridview的行(C#) [英] Colorize Datagridview'S Row (C#)
本文介绍了着色Datagridview的行(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张这样的桌子:
没有名字
1 x
2 y
2 z
2 a
3 b
4 c
5 a
5 b
6 x
6 y
我想要对行进行着色重复数字。
解决方案
处理 RowPrePaint [ ^ ]事件,并在那里设置颜色。
决定使用基础数据的最简单方法,并从那里获取计数。
的属性System.Windows.Forms.DataGridViewCell.Style
是可读/写的:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.style%28v=vs .110%29.aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellstyle(v = vs.110)的.aspx [ ^ ]。
因此,您可以随时修改任何单元格的样式,或者对整行单元格进行修改。
对于整行,您可以使用属性System.Windows.Forms.DataGridViewColumn.DefaultCellStyle
:
https://msdn.microsoft.com/en- us / library / system.windows.forms.datagridviewcolumn.defaultcellstyle(v = vs.110).aspx [ ^ ],
https://msdn.microsoft.com/en-us/library/ system.windows.forms.datagridviewcolumn%28v = vs.110%29.aspx [ ^ ]。
-SA
I have a table like this:
no name
1 x
2 y
2 z
2 a
3 b
4 c
5 a
5 b
6 x
6 y
I want to colorize the rows with duplicate numbers.
解决方案
Handle the RowPrePaint[^] event, and set the colour there.
The easiest way to decide what colour would be to use the underlying data, and get the count from there.
The property ofSystem.Windows.Forms.DataGridViewCell.Style
is read/write:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.style%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellstyle(v=vs.110).aspx[^].
So, you can always modify the style of any cell at any time, or do so for the whole row of cells.
For the whole row, you can use the propertySystem.Windows.Forms.DataGridViewColumn.DefaultCellStyle
:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.defaultcellstyle(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn%28v=vs.110%29.aspx[^].
—SA
这篇关于着色Datagridview的行(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文