With Janus GridEx there are many events which trap edits. Often I want to validate the record before allowing it to be added, or checking that an edited record is valid.
The UpdatingCell even can be good for this, but what if a users adds a new record, and does not edit a cell, leaving it blank, which violates your system rules. In this case it is best to use the AddingRecord event and get the row and check that
Private Sub GridEX1_AddingRecord(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles GridEX1.AddingRecord
Dim newRow As Janus.Windows.GridEX1.GridEXRow = GridEX1.GetRow()
If newRow.Cells("my column name").Value.ToString = "" Then
GridEX1.CancelCurrentEdit() 'If rule is violated you can reject the row using this method
Exit Sub
End If
End Sub
Private Sub GridEx1_UpdatingCell(ByVal sender As Object, ByVal e As Janus.Windows.GridEX.UpdatingCellEventArgs) Handles GridEx1.UpdatingCell
Try
If e.Column.Key = "My Column Name" Then
If e.Value.ToString.Trim = "" Then
MessageBox.Show("Holiday name should not be blank", "Holidays", MessageBoxButtons.OK, MessageBoxIcon.Error)
e.Cancel = True
End If
End If
Catch ex As Exception
'Error Handling Here
End Try
End Sub
No comments:
Post a Comment