Before RightClick Event Handler

You can use the BeforeRightClick event to perform data validation of the list object. Listing 7.30 uses the same validation code we used in the BeforeAddDataBoundRow, but here it enables you to check the validation before typing all the required information into the remaining columns. Setting Cancel to True cancels the default behavior associated with right-clicking the list object (in this case, displaying the context menu). If a validation fails, a message box is displayed; otherwise, the default behavior associated with right-clicking the list object occurs.

Listing 7.30. Validating data entered in a ListObject when the list is right-clicked

Private Sub List1_BeforeRightClick(ByVal Target As _ Microsoft.Office.Interop.Excel.Range, _

ByRef Cancel As Boolean) Handles List1.BeforeRightClick

Dim currentRange As Excel.Range = Me.Application.Selection

If currentRange.Value IsNot Nothing Then

If CType(currentRange.Columns(1), Excel.Range).Value < _ Today Then

MsgBox("Appointments cannot be scheduled" _

& " prior to today's date.") Cancel = True

End If End If

End Sub

0 0

Post a comment