Type | Description | |||
Parent as HITEM | A long expression that indicates the handle of the parent item where the object will be inserted. If the argument is missing then the InsertObjectItem property inserts the object as a root item. If the Parent property is referring a locked item ( ItemLocked property ), the InsertObjectItem property doesn't insert a new child, instead places the object to the locked item that's specified by the Parent property. | |||
UserData as Variant | A VARIANT expression being specified at creating time, which can be accessed during the AddItem event. The ItemData property indicates the extra data associated with any item. The ItemData property is initalized with the value of the UserData parameter. | |||
Obj as Variant | A object being hosted. The most common type is System.Windows.Forms.Control from the /NET framework. Generally, the Obj could be any control that can be placed to a form or dialog and it is visible at runtime. The Obj can not be a windowless control ( a control that does not require a window, such a line or circle ). The Obj parameter could be also an ActiveX control ( that has already being placed in the form/dialog) in this case, the Obj should be the result of the property Object() (VB6, VFP ). GetOcx() property. Finally, the Obj parameter could be of long type ( numeric ) in which case it should refer the handle of a window that follows to be hosted in the newly created item. The handle of the window can be obtained as m_hWnd member of MFC classes, hWnd or Handle property in the /NET framework. After creating the host, the ItemObject property can be used to retrieve the originally object ( Obj parameter ). |
Return | Description | |||
HITEM | A long expression that indicates the item's handle that indicates the newly created item. |
The following screen shot shows the /NET assembly ( master control ) that hosts a System.Windows.Forms.PropertyGrid control from the /NET framework ( inner control ):
The following samples describes:
The following VB/NET sample inserts a child item that hosts an inner exgrid/net component:
With Exgrid1 .BeginUpdate() With .Items Dim hx As Integer = .InsertObjectItem(.FocusItem, Nothing, New exontrol.EXGRIDLib.exgrid()) If (hx <> 0) Then With .get_ItemObject(hx) .BeginUpdate() .Columns.Add("inner column") .Items.AddItem("inner item") .EndUpdate() End With End If End With .EndUpdate() End With
The following C# sample inserts a child item that hosts an inner exgrid/net component:
exgrid1.BeginUpdate(); int hx = exgrid1.Items.InsertObjectItem(exgrid1.Items.FocusItem, null, new exontrol.EXGRIDLib.exgrid()); if ( hx != 0 ) { exontrol.EXGRIDLib.exgrid innerGrid = exgrid1.Items.get_ItemObject(hx) as exontrol.EXGRIDLib.exgrid; if ( innerGrid != null ) { innerGrid.BeginUpdate(); innerGrid.Columns.Add("inner column"); innerGrid.Items.AddItem("inner item"); innerGrid.EndUpdate(); } } exgrid1.EndUpdate();
The following screen shot shows the /NET assembly ( master control ) that hosts another /NET assembly control ( inner control ):
The following VB/NET sample inserts a child item that hosts an inner System.Windows.Forms.PropertyGrid component from the /NET framework:
With Exgrid1 .BeginUpdate() With .Items Dim hx As Integer = .InsertObjectItem(.FocusItem, Nothing, New System.Windows.Forms.PropertyGrid()) If (hx <> 0) Then With .get_ItemObject(hx) .SelectedObject = Exgrid1 End With End If End With .EndUpdate() End With
The following C# sample inserts a child item that hosts an inner System.Windows.Forms.PropertyGrid component from the /NET framework:
exgrid1.BeginUpdate(); int hx = exgrid1.Items.InsertObjectItem(exgrid1.Items.FocusItem, null, new System.Windows.Forms.PropertyGrid()); if ( hx != 0 ) { System.Windows.Forms.PropertyGrid innerPropertyGrid = exgrid1.Items.get_ItemObject(hx) as System.Windows.Forms.PropertyGrid; if (innerPropertyGrid != null) innerPropertyGrid.SelectedObject = exgrid1; } exgrid1.EndUpdate();
You can handle the events for the inner controls as you would do if they has been placed to a form or dialog.
In C# you have to use the += operator while in VB/NET you can use the AddHandler as shown in the following samples:
The following VB/NET sample adds a handler for the DblClick event:
' innerGrid_DblClick handles event for the inner grid, where the sender is the object iself AddHandler innerGrid.DblClick, AddressOf innerGrid_DblClick Private Sub innerGrid_DblClick(ByVal sender As Object, ByVal Shift As Short, ByVal X As Integer, ByVal Y As Integer) MessageBox.Show("innergrid dbl click") End Sub
The following C# sample adds a handler for the DblClick event:
// innerGrid_DblClick handles event for the inner grid, where the sender is the object iself innerGrid.DblClick += new exontrol.EXGRIDLib.exgrid.DblClickEventHandler(innerGrid_DblClick); void innerGrid_DblClick(object sender, short Shift, int X, int Y) { MessageBox.Show("innergrid dbl click"); }
The sender parameter of the event identifies the object itself that fired the event, so you can use the handler for multiple instances of the same type. The sender will make the distinction. Now, in case you want to identify actually the item in the master control that hosts the sender, you can use the FindItemData property and set the UserData parameter of the InsertObjectItem property the same as for the Obj parameter. This way the FindItemData(sender) will indicates the handle of the hosts the sender. In this case inserting the inner control should look like follows:
VB/NET
With Exgrid1 .BeginUpdate() With .Items Dim innerGrid As exontrol.EXGRIDLib.exgrid = New exontrol.EXGRIDLib.exgrid() Dim hx As Integer = .InsertObjectItem(.FocusItem, innerGrid, innerGrid) If (hx <> 0) Then With innerGrid .BeginUpdate() .Columns.Add("inner column") .Items.AddItem("inner item") .EndUpdate() End With End If AddHandler innerGrid.DblClick, AddressOf innerGrid_DblClick End With .EndUpdate() End With
C#
exgrid1.BeginUpdate(); exontrol.EXGRIDLib.exgrid innerGrid = new exontrol.EXGRIDLib.exgrid(); int hx = exgrid1.Items.InsertObjectItem(exgrid1.Items.FocusItem, innerGrid, innerGrid); if (hx != 0) { innerGrid.BeginUpdate(); innerGrid.Columns.Add("inner column"); innerGrid.Items.AddItem("inner item"); innerGrid.EndUpdate(); } innerGrid.DblClick += new exontrol.EXGRIDLib.exgrid.DblClickEventHandler(innerGrid_DblClick); exgrid1.EndUpdate();