Setting the back brush color of a grid cell to a color picked from a color dialog control
Posted on 2006-04-07
I am trying to set the background color of individual cells in a grid to different colors that have been selected from a color dialog control.
For a test I selected a color from a color dialog control and saved it to an integer variable as follows:
colorArgb = Me.Label1.ForeColor.ToArgb
The test form contains a grid and I have the following subroutines to format the grid cells:
AddCellFormattingColumnStyles(Me.grdColorcodes, New FormatCellEventHandler(AddressOf FormatGridCells))
Private Sub AddCellFormattingColumnStyles(ByVal grid As DataGrid, ByVal handler As FormatCellEventHandler)
Dim ts As DataGridTableStyle
ts = New DataGridTableStyle
Dim dt As DataView
dt = CType(grid.DataSource, DataView)
ts.MappingName = "codetable"
Private Sub FormatGridCells(ByVal sender As Object, ByVal e As DataGridFormatCellEventArgs)
If e.row = 4 and e.Column = 3 Then
e.BackBrush = Color.FromArgb(colorArgb)
The problem is that the statement 'e.BackBrush = Color.FromArgb(colorArgb)' is invalid and I get the error message "Value of "System.Drawing.Color" cannot be converted to 'System.Drawing.Brush'".
Can I some how use the value in the variable 'colorArgb' to set the color of a specific grid cell or is there another way to do so?
Thanks in advance