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: Gantt1.Items.RemoveItem Gantt1.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 RemoveSelection method removes the selected items (including the descendents).

The following VB sample removes recursively an item:

Private Sub RemoveItemRec(ByVal t As EXGANTTLibCtl.Gantt, 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( CGantt* pGantt, long hItem )
{
	if ( hItem )
	{
		pGantt->BeginUpdate();
		CItems items = pGantt->GetItems();
		long hChild = items.GetItemChild( hItem );
		while ( hChild )
		{
			long nNext = items.GetNextSiblingItem( hChild );
			RemoveItemRec( pGantt, hChild );
			hChild = nNext;
		}
		items.RemoveItem( hItem );
		pGantt->EndUpdate();
	}
}

The following VB.NET sample removes recursively an item:

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

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

LPARAMETERS h

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