Click here to Skip to main content
15,906,624 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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.
Posted
Updated 19-May-15 3:02am
v3

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.
 
Share this answer
 
The property of System.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 property 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
 
Share this answer
 
Comments
Parazival 19-May-15 8:52am    
THANKSS but i am not pointing on colour
just how to count the numbers in one column if any num more than one time that row should be in colour


thankss for your replay
Sergey Alexandrovich Kryukov 19-May-15 8:56am    
That wasn't a reply, but a complete answer. Yes, you were "pointing on color", please don't deny the obvious.

You can count anything you want using the property System.Windows.Forms.DataGridViewCell.Value, cast to appropriate type you can check using System.Windows.Forms.DataGridViewCell.ValueType.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900