method Items.Edit ([Item as Variant], [ColIndex as Variant])

Edits a cell.

TypeDescription
Item as Variant A long expression that indicates the item's handle.
ColIndex as Variant A long expression that indicates the column's index, a string expression that indicates the column's caption or the column's key.

The Edit method starts editing an item. The edit operation starts only if the control's AllowEdit property is True. When the edit operation starts the control fires the BeforeCellEdit event. Use the BeforeCellEdit event to cancel the edit operation. When the edit operation ends the control fires the AfterCellEdit event. Use the AfterCellEdit event to change the cell's caption after edit operation ends. Use the SelStart, SelLength properties to specify the coordinates of the text being selected when edit starts. The following code starts editing the first cell: Tree1.Items.Edit Tree1.Items(0), 0. 

The following VB sample changes the cell's caption when the edit operation ends:

Private Sub Tree1_AfterCellEdit(ByVal Item As EXTREELibCtl.HITEM, ByVal ColIndex As Long, ByVal NewCaption As String)
    Tree1.Items.CellCaption(Item, ColIndex) = NewCaption
End Sub

The following VB sample starts editing the cell as soon as the user clicks the item:

Private Sub Tree1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    ' Converts the container coordinates to client coordinates
    X = X / Screen.TwipsPerPixelX
    Y = Y / Screen.TwipsPerPixelY
    Dim h As HITEM
    Dim c As Long
    Dim hit As EXTREELibCtl.HitTestInfoEnum
    ' Gets the item from (X,Y)
    h = Tree1.ItemFromPoint(X, Y, c, hit)
    If Not (h = 0) Then
        With Tree1
            .AllowEdit = True
            With .Items
                .Edit h, 0
            End With
        End With
    End If
End Sub

The following VB.NET sample changes the cell's caption as soon as the edit operation ends.

Private Sub AxTree1_AfterCellEdit(ByVal sender As Object, ByVal e As AxEXTREELib._ITreeEvents_AfterCellEditEvent) Handles AxTree1.AfterCellEdit
    AxTree1.Items.CellCaption(e.item, e.colIndex) = e.newCaption
End Sub

The following C# sample changes the cell's caption as soon as the edit operation ends.

private void axTree1_AfterCellEdit(object sender, AxEXTREELib._ITreeEvents_AfterCellEditEvent e)
{
	axTree1.Items.set_CellCaption( e.item, e.colIndex, e.newCaption );
}

The following C++ sample changes the cell's caption as soon as the edit operation ends.

void OnAfterCellEditTree1(long Item, long ColIndex, LPCTSTR NewCaption) 
{
	m_tree.GetItems().SetCellCaption( COleVariant( Item ), COleVariant( ColIndex ), COleVariant( NewCaption ) );
}

The following VFP sample changes the cell's caption as soon as the edit operation ends.

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

with thisform.Tree1.Items
	.DefaultItem = item
	.CellCaption( 0, colindex ) = newcaption
endwith

Note: A cell is identified by the intersection of an item and a column. Properties that have Item and ColIndex parameters let you specify a cell in different ways. The Item parameter identifies the item, while the ColIndex parameter identifies the column.

The Item parameter can be the handle of an item. The ColIndex parameter can specify the column by its index (a numerical value, see the Column.Index property), by its caption (a string value, see the Column.Caption property), or by a cell handle returned by the ItemCell property.

For example, the following statement sets the Bold property of the cell at the intersection of the first item and the first column. The Item parameter is omitted because the ColIndex parameter receives the cell handle returned by ItemCell.

Tree1.Items.CellBold(, Tree1.Items.ItemCell(Tree1.Items(0), 0)) = True

The same cell can be specified by passing the item handle and the column index separately:

Tree1.Items.CellBold(Tree1.Items(0), 0) = True

You can also specify the column by its caption instead of its numerical index:

Tree1.Items.CellBold(Tree1.Items(0), "ColumnName") = True