UnboundHandler object
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. The UnboundHandler property specifies the control's unbound handler. Currently, the UnboundHandler / IUnboundHandler interface is available for /COM version only.

Here's the IDL definition of the IUnboundHandler interface:

[
    uuid(BA3AA5FA-5B09-40F6-80DF-B051C20150B6),
    pointer_default(unique) 
]
interface IUnboundHandler : IUnknown
{
    [propget, id(1), helpcontext(3001), helpstring("Gets the number of items.")] HRESULT ItemsCount( IDispatch* Source, [out, retval ] long* pVal );
    [id(2), helpcontext(3002), helpstring("The source requires an item.")] HRESULT ReadItem( long Index, IDispatch* Source, long ItemHandle );
}

Here's the IDL definition of the UnboundHandler interface ( this interface is available starting from the version 11.1 ):

[
    uuid(BA3AA5FA-5B09-40F6-80DF-B051C20150B7),
]
dispinterface UnboundHandler
{
    interface IUnboundHandler;
}

The following VB sampledisplays 1,000,000 items in virtual mode:

Implements EXGRIDLibCtl.IUnboundHandler

Private Sub Form_Load()
    With Grid1
        .BeginUpdate
        .Columns.Add("Index").FormatColumn = "value format `0`"
        .VirtualMode = True
        Set .UnboundHandler = Me
        .EndUpdate
    End With
End Sub

Private Property Get IUnboundHandler_ItemsCount(ByVal Source As Object) As Long
    IUnboundHandler_ItemsCount = 1000000
End Property

Private Sub IUnboundHandler_ReadItem(ByVal Index As Long, ByVal Source As Object, ByVal ItemHandle As Long)
    With Source.Items
        .CellValue(ItemHandle, 0) = Index + 1
    End With
End Sub

The following VB/NET sampledisplays 1,000,000 items in virtual mode:

Public Class Form1
    Implements EXGRIDLib.IUnboundHandler

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With AxGrid1
            .BeginUpdate()
            .Columns.Add("Index").FormatColumn = "value format `0`"
            .VirtualMode = True
            .UnboundHandler = Me
            .EndUpdate()
        End With
    End Sub

    Public ReadOnly Property ItemsCount(ByVal Source As Object) As Integer Implements EXGRIDLib.IUnboundHandler.ItemsCount
        Get
            ItemsCount = 10000000
        End Get
    End Property

    Public Sub ReadItem(ByVal Index As Integer, ByVal Source As Object, ByVal ItemHandle As Integer) Implements EXGRIDLib.IUnboundHandler.ReadItem
        With Source.Items
            .CellValue(ItemHandle, 0) = Index + 1
        End With
    End Sub
End Class

The following C# sampledisplays 1,000,000 items in virtual mode:

public partial class Form1 : Form, EXGRIDLib.IUnboundHandler
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        axGrid1.BeginUpdate();
        (axGrid1.Columns.Add("Index") as EXGRIDLib.IColumn).FormatColumn = "value format `0`";
        axGrid1.VirtualMode = true;
        axGrid1.UnboundHandler = this;
        axGrid1.EndUpdate();
    }

    public int get_ItemsCount(object Source)
    {
        return 1000000;
    }

    public void ReadItem(int Index, object Source, int ItemHandle)
    {
        (Source as EXGRIDLib.IGrid).Items.set_CellValue(ItemHandle, 0, Index + 1);
    }
}

The following VFP 9 sample displays 1,000,000 items in virtual mode:

with thisform.Grid1
	.Columns.Add("Index").FormatColumn = "value format `0`"
	.VirtualMode = .T.
	.UnboundHandler = newobject('UnboundHandler', 'class1.prg')
endwith

where the class1.prg is:

define class UnboundHandler as session OLEPUBLIC

implements IUnboundHandler in "ExGrid.dll"
function IUnboundHandler_get_ItemsCount(Source)	
	return 1000000
endfunc
function IUnboundHandler_ReadItem(Index, Source, ItemHandle)
	With Source.Items
        .CellValue(ItemHandle, 0) = Index + 1 
    EndWith
endfunc

implements UnboundHandler in "ExGrid.dll"
function UnboundHandler_get_ItemsCount(Source)	
	return this.IUnboundHandler_get_ItemsCount(Source)
endfunc
function UnboundHandler_ReadItem(Index, Source, ItemHandle)
	return this.IUnboundHandler_ReadItem(Index, Source, ItemHandle)
endfunc

enddefine

The following VFP 7 and VFP 8 sample displays 1,000,000 items in virtual mode:

with thisform.Grid1
	.Columns.Add("Index").FormatColumn = "value format `0`"
	.VirtualMode = .T.
	.UnboundHandler = newobject('UnboundHandler', 'class1.prg')
endwith

where the class1.prg is:

define class UnboundHandler as custom

implements IUnboundHandler in "ExGrid.dll"

function IUnboundHandler_get_ItemsCount(Source)	
	return 10000000
endfunc

function IUnboundHandler_ReadItem(Index, Source, ItemHandle)
	With Source.Items
		.DefaultItem = ItemHandle
        .CellValue(0, 0) = Index + 1
    EndWith
endfunc

enddefine 

 

The UnboundHandler / IUnboundHandler interface requires the following properties and methods:

NameDescription
ItemsCountGets the number of items.
ReadItemThe source requires an item.