Friday, January 29, 2010

Dynamic Cell Formatting


For i As Integer = 0 To Me.DataGridView1.Columns.Count - 1
Me.DataGridView1.Columns(i).Name = Me.DataGridView1.Columns(i).DataPropertyName

Private Sub dataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As DataGridViewCellFormattingEventArgs) _
Handles DataGridView1.CellFormatting
If Me.DataGridView1.Columns(e.ColumnIndex).Name = "SHORT_NAME" Then

If e.Value IsNot Nothing Then
' If the value of the cell is "Inactive" AND this form's inactiveCustomersCheckBox control is checked..
If e.Value.ToString = "LHH" Then
' Set the BackColor of the cell to yellow.

e.CellStyle.BackColor = Color.Red
ElseIf e.Value.ToString = "LLH" Then

e.CellStyle.BackColor = Color.Yellow
ElseIf e.Value.ToString = "LLO" Then
e.CellStyle.BackColor = Color.Red
e.CellStyle.BackColor = Color.White
End If
End If
End If

End Sub



Realted Links:

No comments:

Post a Comment