Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Nov 6, 1998



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Add Columns to a Standard VB List Box

Use the Win32 API to set tab stops in a Visual Basic list box by creating these declarations and routine in a module:

 Public Const LB_SETTABSTOPS = &H192
Declare Function SendMessage Lib "user32" _
	Alias "SendMessageA" (ByVal hwnd As Long, _
	ByVal wMsg As Long, ByVal wParam As Long, _
	lParam As Any)As Long
Sub SetListTabStops(iListHandle As Long)
' sets 2 tab stops in a list box at the 24th 
' and 48th character
' iListHandle = the window handle of the list box
Dim iNumColumns As Long
Dim iListTabs(1) As Long
Dim Ret As Long
	iNumColumns = 2

	iListTabs(0) = 96  ' 96/4 = 24 characters
	iListTabs(1) = 192 ' 192/4 = 48 characters
	Ret = SendMessage(iListHandle, _
		LB_SETTABSTOPS, iNumColumns, iListTabs(0))
End Sub

In your form, create a list box called lstMyListBox. Call this routine in the form load to set your tab stops:

 Call SetListTabStops(lstMyListBox.hwnd)

Then add items to the list box using vbTab:

 lstMyListBox.AddItem "Column 1 data" & _
	vbTab & "Column 2 data"
Catherine Spence
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date