-
I found this doc (Below) on how to add tabs/columns to a list box but I was wonder also how to do the push button tabs that let you sort the data. For example: In Windows explorier you have sorting tabs that let you sort by name, file size, date, etc...
Can this be done for a list box? if not what else could i use.
This code is from vb-world
Code:
Setting Tab Stops in a ListBox
Want to create a simple list box that shows several fields of data? The columns property of the list box does not do this, but you can use this function to do it.
Public Const LB_SETTABSTOPS As Long = &H192
Public Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Sub DoTabs(lstListBox As ListBox, TabArray() As Long)
'clear any existing tabs
Call SendMessage(lstListBox.hWnd, LB_SETTABSTOPS, 0&, ByVal 0&)
'set list tabstops
Call SendMessage(lstListBox.hWnd, LB_SETTABSTOPS, _
CLng(UBound(TabArray)) + 1, TabArray(0))
End Sub
First, set up the columns:
Dim Tabs(2) As Long
Tabs(0) = 0
Tabs(1) = 100
Tabs(2) = 200
DoTabs List1, Tabs
Then, add your items:
List1.AddItem "John" & vbTab & "Percival" & vbTab & "Content Editor"
List1.AddItem "James" & vbTab & "Limm" & vbTab & "Senior Editor"
-
use a list view instead (microsoft windows common controls 6.0) this does everything you need without API calls.
regards
Chris
-
Or use a datagrid bound to an ADO control.
The code below will sort any column when you click on it.
Code:
Private Sub DataGrid1_HeadClick(ByVal ColIndex As Integer)
Adodc1.RecordSource = "Select * From user Order By " & _
DataGrid1.Columns(ColIndex).DataField
Adodc1.Refresh
End Sub
[Edited by jbart on 09-15-2000 at 02:06 PM]
-
Chris,
Thanks for pointing me towards the ListView. I had never used it before, but will in the future.
If anyone is interested, there is an excellent example of using the ListView control and sorting the columns in MSDN under the ColumnClick Event.