method Items.RemoveItem (Item as HITEM)

Removes a specific item.

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

The RemoveItem method removes an item. The RemoveItem method does not remove the item, if it contains child items. The following sample removes the first item: G2antt1.Items.RemoveItem G2antt1.Items(0). 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 removes all bars and links related to the item. The RemoveSelection method removes the selected items (including the descendents). The RemoveSelection method removes the selected objects (bars or links) within the chart. The RemoveSelection method removes the selected links/bars from the chart if exists, else it removes the selected items (including the descendents).

The following VB sample removes recursively an item:

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

The following C++ sample removes recursively an item:

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

The following VB.NET sample removes recursively an item:

Shared Sub RemoveItemRec(ByVal t As AxEXG2ANTTLib.AxG2antt, 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(AxEXG2ANTTLib.AxG2antt g2antt, int hItem)
{
	if (hItem != 0)
	{
		EXG2ANTTLib.Items items = g2antt.Items;
		g2antt.BeginUpdate();
		int hChild = items.get_ItemChild(hItem);
		while (hChild != 0)
		{
			int hNext = items.get_NextSiblingItem(hChild);
			RemoveItemRec(g2antt, hChild);
			hChild = hNext;
		}
		items.RemoveItem(hItem);
		g2antt.EndUpdate();
	}
}

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

LPARAMETERS h

with thisform.G2antt1
    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