Type | Description | |||
Item as HITEM | A HITEM expression that indicates the handle of the item where the bars are enumerated. | |||
Variant | A String expression that indicates the key of the first bar in the item, or empty if the item contains no bar. |
To efficiently work with bars within an item, start by using the FirstItemBar and NextItemBar methods, which allow you to iterate through each bar inside the item. The bars are enumerated alphabetically and sorted in ascending order by the Key of the bar, which also determines the Z-Order of the item-bar. When you need to access specific properties of a particular bar, the ItemBar property provides direct access to those details. If you want to add new bars to the item, the AddBar method allows you to insert new bars easily. Additionally, if you need to establish relationships between bars, the AddLink method helps you link one bar to another, forming necessary connections. For situations where you want to enable bar creation directly using the mouse, the AllowCreateBar method grants that functionality, making bar creation more interactive. In cases where you need to remove a specific bar from the item, the RemoveBar method allows you to delete the chosen bar. If your goal is to remove all the bars within the item at once, use the ClearBars method, which clears out every bar associated with that item in one step.
The following VB.NET sample enumerates all items and bars in the control (/NET or /WPF version):
With Exg2antt1 Dim i, h As Integer, key As Object For i = 0 To .Items.ItemCount - 1 h = .Items(i) key = .Items.get_FirstItemBar(h) While TypeOf key Is String Debug.Print("Key = " & key & ", Item " & .Items.get_CellCaption(h, 0)) key = CStr(.Items.get_NextItemBar(h, key)) End While Next End With
The following C# sample enumerates all items and bars in the control (/NET or /WPF version):
for (int i = 0; i < exg2antt1.Items.ItemCount; i++) { int h = exg2antt1.Items[i]; object key = exg2antt1.Items.get_FirstItemBar(h); while (key != null) { System.Diagnostics.Debug.Print("Key = " + key + ", Item " + exg2antt1.Items.get_CellCaption(h, 0)); key = exg2antt1.Items.get_NextItemBar(h, key); } }
The following VB sample enumerates the bars in the item ( h indicates the handle of the item ):
With G2antt1 If Not (h = 0) Then Dim k As Variant k = .Items.FirstItemBar(h) While Not IsEmpty(k) Debug.Print "Key = " & k k = .Items.NextItemBar(h, k) Wend End If End With
The following C++ sample enumerates the bars in the item ( h indicates the handle of the item ):
CItems items = m_g2antt.GetItems(); COleVariant vtBar = items.GetFirstItemBar(h) ; while ( V_VT( &vtBar ) != VT_EMPTY ) { OutputDebugString( V2S( &vtBar ) ); OutputDebugString( "\n" ); vtBar = items.GetNextItemBar( h, vtBar ); }
where the V2S function converts a Variant expression to a string:
static CString V2S( VARIANT* pv, LPCTSTR szDefault = _T("") ) { if ( pv ) { if ( pv->vt == VT_ERROR ) return szDefault; COleVariant vt; vt.ChangeType( VT_BSTR, pv ); return V_BSTR( &vt ); } return szDefault; }
The following VB.NET sample enumerates the bars in the item ( h indicates the handle of the item ):
With AxG2antt1 If Not (h = 0) Then Dim k As Object k = .Items.FirstItemBar(h) While TypeOf k Is String System.Diagnostics.Debug.Print(k.ToString) k = .Items.NextItemBar(h, k) End While End If End With
The following C# sample enumerates the bars in the item ( h indicates the handle of the item ):
object k = axG2antt1.Items.get_FirstItemBar(h); while ( k != null ) { System.Diagnostics.Debug.Print(k.ToString()); k = axG2antt1.Items.get_NextItemBar(h, k); }
The following VFP sample enumerates the bars in the item ( h indicates the handle of the item ):
With thisform.G2antt1 If Not (h = 0) Then local k k = .Items.FirstItemBar(h) do While !empty(k) ?k k = .Items.NextItemBar(h, k) enddo Endif EndWith
In VFP, please make sure that you are using non empty values for the keys. For instance, if you are omitting the Key parameter of the AddBar method, an empty key is missing. If you need to use the FirstItemBar and NextItemBar properties, you have to use non empty keys for the bars.