Saturday, March 24, 2012

Validation in Datagrid

Sir/Madam,
How to write field validations in data grid. I tried with 'BeforecolUpdate' event. There the current value which we have entered is not available for comparison or for any manipulation etc. Here is the part of the code for your verification.

Private Sub grdDataGrid_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
' Column level validations
Dim wvalue As Variant
wvalue = grdDataGrid.Columns(ColIndex).Value && Balu .. This has the
Select Case ColIndex
Case 1 ' For Name
If Len(Trim(wvalue)) = 0 Then
MsgBox "Name must not Be Empty", vbOKOnly, "Customer Name Error"
grdDataGrid.Columns(1).Value = OldValue
Cancel = True
End If
End Select
End Sub
The above code is not working. Every it validates only the previous value (i.e value before the modification) and validates it.

Kindly explain what you normally handle the similar situations. If possible send the sample code for my understanding (if permissable)

Thanking You,
N.GanesanTry using the AfterColEdit event. Use a select case based upon the column that has been edited and call the appropiate procedure (written by you) for handling the validation. This works well for me while the BeforeColUpdate Event gave me several different problems.

Good luck!

No comments:

Post a Comment