Adds an expand button to left side of the item even if the item has no child items.
Type | Description | |||
Item as HITEM | A long expression that indicates the item's handle. | |||
Boolean | A boolean expression that indicates whether the control adds an expand button to the left side of the item even if the item has no child items. |
By default, the ItemHasChidren property is False. Use the ItemHasChildren property to build a virtual grid. Use the BeforeExpandItem event to add new child items to the expanded item. Use the ItemChild property to get the first child item, if exists. Use the ItemChild or ChildCount property to determine whether an item contains child items. The control displays a +/- sign to parent items, if the HasButtons property is not empty, the ItemChild property is not empty, or the ItemHasChildren property is True. Use the InsertItem method to insert a new child item. Use the CellData or ItemData property to assign an extra value to a cell or to an item.
The following VB sample inserts a child item as soon as the user expands an item ( the sample has effect only if your control contains items that have the ItemHasChildren property on True ):
Private Sub Grid1_BeforeExpandItem(ByVal Item As EXGRIDLibCtl.HITEM, Cancel As Variant) With Grid1.Items If (.ItemHasChildren(Item)) Then If .ChildCount(Item) = 0 Then Dim h As Long h = .InsertItem(Item, , "new " & Item) End If End If End With End Sub
The following VB sample binds the master control to a table, and displays related tables when the user expands an item/record. The sample uses the DataSource property to bind a record set to the control. The InsertControlItem method inserts an ActiveX inside the item.
Option Explicit Public Function getRS(ByVal q As String) As Object Dim rs As Object, strDatabase strDatabase = App.Path + "\ExontrolDemo.mdb" Set rs = CreateObject("ADODB.Recordset") rs.Open q, "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" & strDatabase, 3, 3, 0 Set getRS = rs End Function Private Sub Form_Load() With Grid1 .BeginUpdate .LinesAtRoot = exLinesAtRoot .MarkSearchColumn = False .ScrollBySingleLine = True .HideSelection = True Set .DataSource = getRS("Transactions") .EndUpdate End With End Sub Private Sub Grid1_AddItem(ByVal Item As EXGRIDLibCtl.HITEM) With Grid1.Items .ItemHasChildren(Item) = .ItemParent(Item) = 0 End With End Sub Private Sub Grid1_BeforeExpandItem(ByVal Item As EXGRIDLibCtl.HITEM, Cancel As Variant) With Grid1.Items If .ItemHasChildren(Item) Then With .ItemObject(.InsertControlItem(Item, "Exontrol.Grid")) .BeginUpdate .MarkSearchColumn = False .HideSelection = True Set .DataSource = getRS("Select * from TransactionDetails where TrnDet_ID = " & Grid1.Items.CellValue(Item, "Trn_ID")) .Columns(0).Visible = False .EndUpdate End With .ItemHasChildren(Item) = False End If End With Grid1.Refresh End Sub
The following VB.NET sample inserts a child item when the user expands an item that has the ItemHasChildren property on True:
Private Sub AxGrid1_BeforeExpandItem(ByVal sender As Object, ByVal e As AxEXGRIDLib._IGridEvents_BeforeExpandItemEvent) Handles AxGrid1.BeforeExpandItem With AxGrid1.Items If (.ItemHasChildren(e.item)) Then If .ChildCount(e.item) = 0 Then Dim h As Long h = .InsertItem(e.item, , "new " & e.item.ToString()) End If End If End With End Sub
The following C# sample inserts a child item when the user expands an item that has the ItemHasChildren property on True:
private void axGrid1_BeforeExpandItem(object sender, AxEXGRIDLib._IGridEvents_BeforeExpandItemEvent e) { EXGRIDLib.Items items = axGrid1.Items; if ( items.get_ItemHasChildren( e.item ) ) if (items.get_ChildCount(e.item) == 0) { items.InsertItem(e.item, null, "new " + e.item.ToString()); } }
The following C++ sample inserts a child item when the user expands an item that has the ItemHasChildren property on True:
#include "Items.h" void OnBeforeExpandItemGrid1(long Item, VARIANT FAR* Cancel) { CItems items = m_grid.GetItems(); if ( items.GetItemHasChildren( Item ) ) if ( items.GetChildCount( Item ) == 0 ) { COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR; items.InsertItem( Item, vtMissing, COleVariant( "new item" ) ); } }
The following VFP sample inserts a child item when the user expands an item that has the ItemHasChildren property on True( BeforeExpandItem event ):
*** ActiveX Control Event *** LPARAMETERS item, cancel with thisform.Grid1.Items if ( .ItemHasChildren( item ) ) if ( .ChildCount( item ) = 0 ) .InsertItem(item,"","new " + trim(str(item))) endif endif endwith