Click here to Skip to main content
15,945,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using VS2010 VB.NET, I have a datagridview (dgv) where I set the background color of cells according to a certain value. This particular cell does not store any information and therefore I can not use the data in that cell to determine the background color.

My current attempts are a complete failure and MSDN is only particular to "setting" and not "getting" the background color of a cell.

Code I've tried

VB
if dgvNotes.Rows(clickedCell.RowIndex).Cells(1).Style.BackColor.ToString = "Red" then

if dgvNotes.Rows(clickedCell.RowIndex).Cells(1).Style.BackColor = Color.Red then


I am not able to find much information on the topic as most of the posts on various coding sites focusses on "setting" the background color.

Is there any way that I can determine cell background color after the dgv was populated ?

Thanks
Posted
Updated 24-May-14 2:34am
v2
Comments
Kenneth Haugland 24-May-14 9:04am    
This looks like WinForms? or is it WPF?
Tino Fourie 24-May-14 9:40am    
WinForms... I thought that "VS2010 VB.Net" would be enough not to confuse other members between WPF and VB. My bad if it was not clear enough though.
Kenneth Haugland 24-May-14 9:55am    
WPF can be used with C++ C# and VB.NET so you need to be spesific.

1 solution

VB
Dim CellBkColor As System.Drawing.Color = dgvNotes.Rows(e.RowIndex).Cells(1).Style.BackColor
MsgBox(CellBkColor.ToString)


That is the solution I was looking. Originally from http://stackoverflow.com/questions/23844778/how-to-get-the-style-backcolor-of-a-datagridview-cell[^]
 
Share this answer
 
v2

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