event Edit (Item as HITEM, ColIndex as Long, Cancel as Boolean)
Occurs just before editing the focused cell.

 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 state is changed.  
   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.  
   Cancel as Boolean A boolean expression that indicates whether the editing operation is canceled.  

The Edit event is fired when the edit operation is about to begin. Use the Edit event to disable editing specific cells. The Edit event is not fired if the user changes programmatically the CellValue property. Use the EditOpen event to notify your application that editing the cell started. Use the EditClose event to notify your application that editing the cell ended. Use the Change event to notify your application that user changes the cell's value. Use the Edit method to edit a cell by code. Use the CellEditor or Editor property to assign an editor to a cell or to a column.

The edit events are fired in the following order:

  1. Edit event. Prevents editing cells, before showing the cell's editor.

  2. EditOpen event. The edit operation started, the cell's editor is shown. The Editing property gives the window's handle of the built-in editor being started.

  3. Change event. The Change event is fired only if the user types ENTER key, or the user selects a new value from a predefined data list.

  4. EditClose event. The cell's editor is hidden and closed.

The following VB sample disables editing cells in the first column:

Private Sub Grid1_Edit(ByVal Item As EXGRIDLibCtl.HITEM, ByVal ColIndex As Long, Cancel As Boolean)
    ' Cancels editing first column
    Cancel = IIf(ColIndex = 0, True, False)
End Sub

The following VB sample changes the cell's value to a default value, if the user enters an empty value:

Private Sub Grid1_Edit(ByVal Item As EXGRIDLibCtl.HITEM, ByVal ColIndex As Long, Cancel As Boolean)
    ' Sets the 'default' value for empty cell
    With Grid1.Items
        If (Len(.CellValue(Item, ColIndex)) = 0) Then
            .CellValue(Item, ColIndex) = "default"
        End If
    End With
End Sub

The following C++ sample disables editing cells in the first column:

void OnEditGrid1(long Item, long ColIndex, BOOL FAR* Cancel) 
{
	if ( ColIndex == 0 )
		*Cancel = TRUE;
}

The following VB.NET sample disables editing cells in the first column:

Private Sub AxGrid1_EditEvent(ByVal sender As Object, ByVal e As AxEXGRIDLib._IGridEvents_EditEvent) Handles AxGrid1.EditEvent
	If (e.colIndex = 0) Then
		e.cancel = True
	End If
End Sub

The following C# sample disables editing cells in the first column:

private void axGrid1_EditEvent(object sender, AxEXGRIDLib._IGridEvents_EditEvent e)
{
	if (e.colIndex == 0)
		e.cancel = true;
}

The following VFP sample disables editing cells in the first column:

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

if ( colindex = 0 )
	cancel = .t.
endif

 


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