Color DataGridView cell on exception
Hi,
I'm using VB.NET 2005, and would like to color a cell on a DataGridView if an exception has been invoked. I have the following code snippet:
' ############ GET THE NEW 'FROM' DATE ############
Try
tblRow.Item("From") = Convert.ToDateTime(strNewFromDate)
Catch ex As Exception
' Problem with this date field, so leave blank
' Add 1 to the number of warnings count
intNumberOfWarnings += 1
' Colour the cell in error
End Try
Is there a clever bit of code I need to use that will allow me to color this particular cell?
# 1 Re: Color DataGridView cell on exception
This is just a starting point for you. You'll have to tweak it a bit to make it work for you.
dgv.CurrentRow.DefaultCellStyle.BackColor = Color.BlanchedAlmond
this will at least highlight the entire row. Play around with currentrow.currentcell, might be what your looking for. Hope this helps.
:)
jb
# 2 Re: Color DataGridView cell on exception
Thanks for the tip.
I've collected the rows and cells "in error" in an array, and I've looped through the array with the following line:
Me.DataGridView1.Rows(arWarningRow(intArrayPosition)).Cells(arWarningCell(intArrayPosition )).style.BackColor = Color.Yellow
Works well!