property Grid.UnboundHandler as IUnboundHandler
Specifies the control's unbound handler.

 TypeDescription 
   IUnboundHandler An object that implements the IUnboundHandler interface.  
The control supports unbound mode. In unbound mode, the user is responsible for retrieving items. The unbound mode and virtual unbound modes were provided to let user displays large number of items. In order to let the control works in unbound mode, the user has to implement the  IUnboundHandler notification interface. Use the VirtualMode property to run the control in virtual mode. Use the RemoveAllItems method to remove all items from the control, after setting the UnboundHandler property to nothing.  Use the BeginUpdate and EndUpdate methods, or Refresh method after setting the UnboundHandler property, to reflect the changes in the control's client area. 

If the VirtualMode property is True and the DataSource property is set ( not empty ), the control provides an internal object that implements the IUnboundHandler interface to provide data for the control from the data source.

The following VB sample shows how to implement the IUnboundHandler interface:

Option Explicit
Implements IUnboundHandler

Private Sub Form_Load()
    With Grid1
        .BeginUpdate
            .FullRowSelect = False

            ' Adds two columns
            With .Columns
                Dim i As Long
                For i = 0 To 1
                    With .Add("Column " & i + 1).Editor
                        .EditType = EditTypeEnum.EditType
                    End With
                Next
            End With
            Set .UnboundHandler = Me
        .EndUpdate
    End With
End Sub

Private Property Get IUnboundHandler_ItemsCount(ByVal Source As Object) As Long
    ' The control requires the number of items. the Set .UnboundHandler = Me invokes the IUnboundHandler_ItemsCount method
    IUnboundHandler_ItemsCount = 16
End Property

Private Sub IUnboundHandler_ReadItem(ByVal Index As Long, ByVal Source As Object, ByVal ItemHandle As Long)
    ' The control requires an item
    With Grid1.Items
        .CellValue(ItemHandle, 0) = Index
        .CellValue(ItemHandle, 1) = Index + 1
    End With
End Sub

Running the UnboundMode in VFP 7.0 or greater

  1. Create a PRG file, say, CLASS1.PRG to define a class to implement the IUnboundHandler interface:
    define class UnboundHandler as custom
    	implements IUnboundHandler in "ExGrid.dll"
    	
    	function IUnboundHandler_get_ItemsCount(Source)	
    		return 10000000	&& we are going to have that many virtual items
    	endfunc
    
    	function IUnboundHandler_ReadItem(Index, Source, ItemHandle)
    		With Source.Items
    		.DefaultItem = ItemHandle
            		.CellValue(0, 0) = 'Virtual Item ' + transform(Index+1)	&& in this example, just set text in Column 0 
    		EndWith
    	endfunc
    
    enddefine
  2. Set up ExGrid's properties as follows (in the example, it is done by Form1.Init)
    with thisform.Grid1
    	.Columns.Add("Column 0")
    	.UnboundHandler = newobject('UnboundHandler', 'class1.prg')
    endwith	
  3. You can also use Virtual Mode to scan a table, say, MyCursor, in natural order.
function IUnboundHandler_get_ItemsCount(Source)	
	return reccount('MyCursor')
endfunc

function IUnboundHandler_ReadItem(Index, Source, ItemHandle)
	select MyCursor
	go Index+1
	With Source.Items
		.DefaultItem = ItemHandle
        	.CellValue(0, 0) = 'Virtual Item ' + MyCursor.Field1
	EndWith
endfunc
enddefine

Please check also the VirtualMode property that includes multiple samples. The setup program installs a sample VC\UnboundMode, for C++ version.



Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.