event ValidateValue (Item as HITEM, ColIndex as Long, NewValue as Variant, ByRef Cancel as Boolean)
Occurs before user changes the cell's value.

TypeDescription
Item as HITEM A long expression that determines the item's handle. If the Item parameter is 0, and the ColIndex property is different than zero, the ColIndex indicates the handle of the cell where the change occurs.
ColIndex as Long A long expression that indicates the column's index, if the Item parameter is not zero, a long expression that indicates the handle of the cell if the Item parameter is 0.
NewValue as Variant A Variant value that indicates the value being validated.
Cancel as Boolean (By Reference) A boolean expression that indicates whether the value is valid or not. By default, the Cancel parameter is False, and so the NewValue parameter is valid. If the Cancel parameter is set on True, the control considers the NewValue being a non valid value, so the Change event is not fired.
The ValidateValue event notifies your application that the user is about to change the cell's value using the control's UI. Use the ValidateValue event to prevent users enter wrong values to the cells. The ValidateValue event is fired only if the CauseValidateValue property is not zero and the user alters the focused value. The validation can be done per cell or per item, in other words, the validation can be made if the user leaves the focused cell, or focused item. If the Cancel parameter is True, the user can't move the focus to a new cell/item, until the Cancel parameter is False. If the Cancel parameter is False the control fires the Change event to notify your application that the cell's value is changed. Use the Edit method to programmatically edit the focused cell. Call the DiscardValidateValue method to restore back the values being changed during the validation. 

During ValidateValue event, the Items.CellValue(Item,ColIndex) and Items.CellCaption(Item,ColIndex) properties retrieve the original value/caption of the cell. You can access the modified value for any cell in the validating item using the Items.CellValue(-1,ColIndex) and Items.CellCaption(-1,ColIndex), or uses the -1 identifier for the Item parameter of the Items.CellValue and Items.CellCaption properties.

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.

Syntax for ValidateValue event, /NET version, on:

private void ValidateValue(object sender,int Item,int ColIndex,object NewValue,ref bool Cancel)
{
}

Private Sub ValidateValue(ByVal sender As System.Object,ByVal Item As Integer,ByVal ColIndex As Integer,ByVal NewValue As Object,ByRef Cancel As Boolean) Handles ValidateValue
End Sub

Syntax for ValidateValue event, /COM version, on:

private void ValidateValue(object sender, AxEXG2ANTTLib._IG2anttEvents_ValidateValueEvent e)
{
}

void OnValidateValue(long Item,long ColIndex,VARIANT NewValue,BOOL FAR* Cancel)
{
}

void __fastcall ValidateValue(TObject *Sender,Exg2anttlib_tlb::HITEM Item,long ColIndex,Variant NewValue,VARIANT_BOOL * Cancel)
{
}

procedure ValidateValue(ASender: TObject; Item : HITEM;ColIndex : Integer;NewValue : OleVariant;var Cancel : WordBool);
begin
end;

procedure ValidateValue(sender: System.Object; e: AxEXG2ANTTLib._IG2anttEvents_ValidateValueEvent);
begin
end;

begin event ValidateValue(long Item,long ColIndex,any NewValue,boolean Cancel)
end event ValidateValue

Private Sub ValidateValue(ByVal sender As System.Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_ValidateValueEvent) Handles ValidateValue
End Sub

Private Sub ValidateValue(ByVal Item As EXG2ANTTLibCtl.HITEM,ByVal ColIndex As Long,ByVal NewValue As Variant,Cancel As Boolean)
End Sub

Private Sub ValidateValue(ByVal Item As Long,ByVal ColIndex As Long,ByVal NewValue As Variant,Cancel As Boolean)
End Sub

LPARAMETERS Item,ColIndex,NewValue,Cancel

PROCEDURE OnValidateValue(oG2antt,Item,ColIndex,NewValue,Cancel)
RETURN

Syntax for ValidateValue event, /COM version (others), on:

<SCRIPT EVENT="ValidateValue(Item,ColIndex,NewValue,Cancel)" LANGUAGE="JScript">
</SCRIPT>

<SCRIPT LANGUAGE="VBScript">
Function ValidateValue(Item,ColIndex,NewValue,Cancel)
End Function
</SCRIPT>

Procedure OnComValidateValue HITEM llItem Integer llColIndex Variant llNewValue Boolean llCancel
	Forward Send OnComValidateValue llItem llColIndex llNewValue llCancel
End_Procedure

METHOD OCX_ValidateValue(Item,ColIndex,NewValue,Cancel) CLASS MainDialog
RETURN NIL

void onEvent_ValidateValue(int _Item,int _ColIndex,COMVariant _NewValue,COMVariant /*bool*/ _Cancel)
{
}

function ValidateValue as v (Item as OLE::Exontrol.G2antt.1::HITEM,ColIndex as N,NewValue as A,Cancel as L)
end function

function nativeObject_ValidateValue(Item,ColIndex,NewValue,Cancel)
return

The following VB sample asks the user to validate the value for each cell that's edited:

Private Sub G2antt_ValidateValue(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal ColIndex As Long, ByVal NewValue As Variant, Cancel As Boolean)
    Cancel = True ' Causes all cells to be invalid
    If MsgBox("The ValidateValue event just occurs. Do the change with this value '" & NewValue & "'?", vbYesNo) = vbYes Then
        Cancel = False ' Only cells where user selects the Yes button, are valid
    End If
    G2antt.Edit ' Continue editing a cell.
End Sub

The following C++ sample asks the user to validate the value for each cell that's edited:

CString V2S( const VARIANT* pvtValue )
{
	COleVariant vt;
	vt.ChangeType( VT_BSTR, (LPVARIANT)pvtValue );
	return V_BSTR( &vt );
}

void OnValidateValueG2antt1(long Item, long ColIndex, const VARIANT FAR& NewValue, BOOL FAR* Cancel) 
{
	*Cancel = TRUE;	// Causes all cells to be invalid
	if ( MessageBox( "The ValidateValue event just occurs. Do the change with this value '" + V2S( &NewValue ) + "'?", "Information", MB_YESNO ) == IDYES )
		*Cancel = FALSE; // Only cells where user selects the Yes button, are valid
	COleVariant vtOptional; V_VT(&vtOptional) = VT_ERROR;
	m_g2antt.Edit( vtOptional ); // Continue editing a cell.
}

The following C++ sample asks the user to enter a value greater than 10 on the first column, if the value is less than 10:

Private Sub G2antt_ValidateValue(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal ColIndex As Long, ByVal NewValue As Variant, Cancel As Boolean)
    If (ColIndex = 0) Then
        If (NewValue < 10) Then
            MsgBox "Enter a value greater than 10."
            Cancel = True	' Cancels only the cells with the value less than 10.
            G2antt.Edit ' Continue editing a cell.
        End If
    End If
End Sub

The following VB.NET sample asks the user to validate the values on the first column:

Private Sub AxG2antt1_ValidateValue(ByVal sender As Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_ValidateValueEvent) Handles AxG2antt1.ValidateValue
    If (e.colIndex = 0) Then
        e.cancel = True
        Dim strMessage As String = "The ValidateValue event just occurs. Do the change with this value '" & e.newValue.ToString() & "'?"
        If (MessageBox.Show(strMessage, "Question", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes) Then
            e.cancel = False
        End If
    End If
End Sub

The following C# sample asks the user to validate the values on the first column:

private void axG2antt1_ValidateValue(object sender, AxEXG2ANTTLib._IG2anttEvents_ValidateValueEvent e)
{
	if (e.colIndex == 0)
	{
		e.cancel = true;
		string strMessage = "The ValidateValue event just occurs. Do the change with this value '" + e.newValue.ToString() + "'?";
		if ( MessageBox.Show(strMessage, "Question", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes )
			e.cancel = false;
	}
}

The following VFP sample asks the user to validate the values on the first column:

*** ActiveX Control Event ***
LPARAMETERS item, colindex, newvalue, cancel

with thisform.G2antt1.Items
	if ( colindex = 0 ) 
		cancel = .t.
		local strMessage
		strMessage = "The ValidateValue event just occurs. Do the change with this value '" + newvalue + "'?"
		if ( MessageBox( strMessage, 3 ) = 6 ) 
			cancel = .f.
		endif
	endif
endwith