Changing Colors of Datagrid

I have a VB.NET application running on a HHP handheld (Windows Mobile 2003). I would like the backcolor of the rows of the grid to appear as a particular color depending on their value.

For example:

If Cell = 1, then Backcolor = Red.

If Cell = 2, then Backcolor = Blue.

From reading other posts i understand I have to inherit the dataGridColumnStyle and override the paint method. I have no idea how to do this. Could someone provide a few lines of code to demonstrate

At the moment all I have is this, which only colours the selected cell.

Private Sub grdResults_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdResults.CurrentCellChanged

Dim currentCell As DataGridCell

currentCell = grdResults.CurrentCell

If CStr(grdResults(currentCell.RowNumber, 0)) = "1" Then

grdResults.SelectionBackColor = Color.Red

ElseIf CStr(grdResults(currentCell.RowNumber, 0)) = "2" Then

grdResults.SelectionBackColor = Color.Blue

ElseIf CStr(grdResults(currentCell.RowNumber, 0)) = "3" Then

grdResults.SelectionBackColor = Color.Green

End If

End Sub



Answer this question

Changing Colors of Datagrid

  • John12312

    I cannot open the installed program.

    My current version of VS 2003 is 7.1.6030.

    It also lists Microsoft .NET framework 1.1 as 1.1.4322. I do have Net framework 2.0 in my list of installed programs in Control Panel.


  • uanmi

    You can only do that by overriding cell painting which is supported from NETCF V2 SP1:



  • pharaonix

    You need VS 2005 SE or above to develop for NETCF V2, VS 2003 is not an option.

    If you have to stay with VS 2003 (or NETCF V1), look into 3rd party grid-like controls instead.



  • Changing Colors of Datagrid