ListBox in Visual Basic .NET

Started by nandagopal, May 20, 2009, 07:09 PM

Previous topic - Next topic

nandagopal

Subroutine SetListBoxTabs defines tabs for a ListBox. It makes a "pinned" array (an array that cannot be moved by Visual Basic) if integers defining the tabs. It uses the SendMessage API function to send the ListBox the LB_SETTABSTOPS message passing it the array. It finishes by freeing the array and refreshing the ListBox.


Private Sub SetListBoxTabs(ByVal list_box As ListBox, ByVal _
    tab_stops() As Integer)
    Dim pinned_array As GCHandle = _
        GCHandle.Alloc(tab_stops, GCHandleType.Pinned)
    SendMessage( _
        list_box.Handle, _
        LB_SETTABSTOPS, _
        New IntPtr(tab_stops.Length), _
        pinned_array.AddrOfPinnedObject)
    pinned_array.Free()

    list_box.Refresh()
End Sub