property G2antt.CauseValidateValue as ValidateValueType
Returns or sets a value that determines whether the ValidateValue event occurs before the user changes the cell's value.

 TypeDescription 
   ValidateValueType A ValidateValueType expression that indicates whether the ValidateValue event is fired when user leaves the focused cell or focused item.  
By default, the CauseValidateValue property is exNoValidate (False). The ValidateValue event is fired only if the CauseValidateValue property is exValidateCell or exValidateItem, once the user alters the focused cell and the user is trying to leave the focused cell or item. Use the exValidateItem option to validate the item once a new item is focused, or use the exValidateCell to validate the cell's value once the user leaves the focused cell. You can use the ValidateValue event to prevent the user enters wrong values to the cells/items. In conclusion, the user can focus a new cell ( in the same item ) while using validation, only if the CauseValidateValue property is exValidateItem. Else, the user can not move the focus to a new cell or items until the user validates the value ( Cancel parameter of the ValidateValue event is False ). Call the DiscardValidateValue method to restore back the values being changed during the validation.

The following VB sample displays a message box with Yes, No and Cancel buttons to validate the changed value:

Private Sub G2antt1_ValidateValue(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal ColIndex As Long, ByVal NewValue As Variant, Cancel As Boolean)
    Cancel = True
    Dim iResult As Long
    i = MsgBox("Validate G2ANTT1 :" & G2antt1.Items.CellCaption(Item, ColIndex ) & " " & NewValue, vbYesNoCancel)
    If (i = vbCancel) Then
        G2antt1.DiscardValidateValue
    Else
        Cancel = i = vbNo
    End If
End Sub 

The ValidateValue event provides the Cancel parameter which can be used to validate the value being changed. The sample calls the DiscardValidateValue method if user selects Cancel, so the value are being restored. The validation is accepted once the user selects the Yes button. If No, the validation continues, and if the control's AutoEdit property is True, the control re-opens the editor for validation.

During the validation you may have the following order of the events:

The ValidateValue event is not fired if the CellValue property is called during the event.

 


Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.