method Items.RemoveItem (Item as HITEM)

Removes the given item.

TypeDescription
Item as HITEM A long expression that indicates the item's handle being removed.

The RemoveItem method removes an item. The RemoveItem method does not remove the item, if it contains child items. Use the RemoveAllItems method to remove all items in the control. Use the BeginUpdate and EndUpdate methods to maintain performance while removing the items. The RemoveItem method can't remove an item that's locked. Instead you can use the LockedItemCount property to add or remove locked items. Use the IsItemLocked property to check whether an item is locked. The RemoveItem method is not available if the control is running in the virtual mode. The RemoveSelection method removes the selected items (including the descendents).

The following VB sample removes recursively an item:

Private Sub RemoveItemRec(ByVal t As EXGRIDLibCtl.Grid, ByVal h As HITEM)
    t.BeginUpdate
        With t.Items
            If (.ChildCount(h) > 0) Then
                Dim hChild As HITEM
                hChild = .ItemChild(h)
                While (hChild <> 0)
                    Dim hNext As HITEM
                    hNext = .NextSiblingItem(hChild)
                    RemoveItemRec t, hChild
                    hChild = hNext
                Wend
            End If
        .RemoveItem h
    t.EndUpdate
    End With
End Sub

The following C++ sample removes recursively an item:

void RemoveItemRec( CGrid* pGrid, long hItem )
{
	if ( hItem )
	{
		pGrid->BeginUpdate();
		CItems items = pGrid->GetItems();
		long hChild = items.GetItemChild( hItem );
		while ( hChild )
		{
			long nNext = items.GetNextSiblingItem( hChild );
			RemoveItemRec( pGrid, hChild );
			hChild = nNext;
		}
		items.RemoveItem( hItem );
		pGrid->EndUpdate();
	}
}

The following VB.NET sample removes recursively an item:

Shared Sub RemoveItemRec(ByVal t As AxEXGRIDLib.AxGrid, ByVal h As Integer)
    If Not h = 0 Then
        With t.Items
            t.BeginUpdate()
            Dim hChild As Integer = .ItemChild(h)
            While (hChild <> 0)
                Dim hNext As Integer = .NextSiblingItem(hChild)
                RemoveItemRec(t, hChild)
                hChild = hNext
            End While
            .RemoveItem(h)
            t.EndUpdate()
        End With
    End If
End Sub

The following C# sample removes recursively an item:

internal void RemoveItemRec(AxEXGRIDLib.AxGrid grid, int hItem)
{
	if (hItem != 0)
	{
		EXGRIDLib.Items items = grid.Items;
		grid.BeginUpdate();
		int hChild = items.get_ItemChild(hItem);
		while (hChild != 0)
		{
			int hNext = items.get_NextSiblingItem(hChild);
			RemoveItemRec(grid, hChild);
			hChild = hNext;
		}
		items.RemoveItem(hItem);
		grid.EndUpdate();
	}
}

The following VFP sample removes recursively an item ( removeitemrec method ):

LPARAMETERS h

with thisform.Grid1
    If ( h != 0 ) Then
    	.BeginUpdate()
        local hChild
        With .Items
            hChild = .ItemChild(h)
            do While (hChild != 0)
	            local hNext
	            hNext = .NextSiblingItem(hChild)
	            thisform.removeitemrec(hChild)
                hChild = hNext
            enddo
            .RemoveItem( h )
        EndWith
        .EndUpdate()
    EndIf
endwith