[2005] Datagridview rowprepaint?
Hi!
I have an issue I cant find a solution for.
In ASP.NET it is extremly easy to change a row/cell at databind time depending on what the value is.
I was very surprised that I didnt find such similar events for the datagridview. I did find the rowprepaint event but I am not sure it is suited for the task
The info I need is
column, row and value to bind
kind regards
Henrik
Re: [2005] Datagridview rowprepaint?
Yes, you can handle the DGV.RowPrePaint event to color the row/cells conditionally. Something like this:
Code:
Private Sub DataGridView1_RowPrePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint
Dim row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
Dim cellValue As Object = row.Cells(0).Value
If cellValue IsNot Nothing AndAlso cellValue.ToString.StartsWith("something") Then
row.DefaultCellStyle.BackColor = Color.Yellow
End If
End Sub
Is it best suited for the task? I don't know, but it works.