I want to change the background colour of rows on a datagrid depending on the value of the 2nd cell in each row.
I've seen a lot of examples of subroutines but I can't see how they these subroutines are called so as to update the datagrid. My datagrid has id="dgrdStock". How can I:
1) get a subroutine to set the colour of rows depending on cell values and
2) apply it to my datagrid?
The code below is lifted and modified from other solutions I've seen - but untested as I don;t know how to call this subroutine.
Sub dgrdStock_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles dgrdStock.CellPainting
Select Case dgrdStock.Rows(e.RowIndex).Cells.Item(2).Value
Case "Available UK"
dgrdStock.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Green
Case "Available Europe"
dgrdStock.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Blue
dgrdStock.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red