event ValidateValue (Item as HITEM, ColIndex as Long, NewValue as Variant, 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 newly cell's value, before passing to the CellValue property.  
   Cancel as Boolean 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 CellValue property is not updated.  
The ValidateValue event notifies your application that the user is about to change the cell's value. Use the ValidateValue to let users enter only valid values to the cells. Use the ValidateValue event to prevent users enter wrong values to the cells. The ValidateValue event is fired only if the CauseValidateValue property is True. If the Cancel parameter is True, the user can't move the focus to a new cell, until the Cancel parameter is False. If the Cancel parameter is True on exit, the control fires the Change event to notify the control that a cell is changed. Use the Edit method to programmatically edit the focused cell. Set the CauseValidateValue property after loading/adding the items, else the ValidateValue event will be fired for each cell that's added.

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

Private Sub Grid_ValidateValue(ByVal Item As EXGRIDLibCtl.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
    Grid.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 OnValidateValueGrid1(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_grid.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 Grid_ValidateValue(ByVal Item As EXGRIDLibCtl.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.
            Grid.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 AxGrid1_ValidateValue(ByVal sender As Object, ByVal e As AxEXGRIDLib._IGridEvents_ValidateValueEvent) Handles AxGrid1.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 axGrid1_ValidateValue(object sender, AxEXGRIDLib._IGridEvents_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.Grid1.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

 


Send comments on this topic.
© 1999-2008 Exontrol Inc, Software. All rights reserved.