devxlogo

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 = &H192Declare Function SendMessage Lib "user32" _	Alias "SendMessageA" (ByVal hwnd As Long, _	ByVal wMsg As Long, ByVal wParam As Long, _	lParam As Any)As LongSub 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 boxDim iNumColumns As LongDim iListTabs(1) As LongDim 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"

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  Seven Service Boundary Mistakes That Create Technical Debt

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.