Datagridview _CellValidating question
I have a datagridview and in the _CellValidating event I am checking a cell to make sure it is filled in. If it is not, I want to stop editing, display a msgbox, and highlight the particular cell. Here is my code :
Code:
If e.ColumnIndex = 2 Then
If e.FormattedValue = "" Then
If Me.dgvFish.IsCurrentCellDirty Then
MsgBox("Sample Number is a required field.")
Me.dgvFish.EndEdit()
e.Cancel = True
Me.dgvFish.Rows(e.RowIndex).Cells(2).Style.BackColor = Color.Aquamarine
End If
End If
End If
For some reason, I can't get the cell's backcolor to be filled in. Any suggestions ? Thanks.
Re: Datagridview _CellValidating question
Try replacing 2 with e.ColumnIndex