| Option Explicit Private Declare Function SendMessage Lib _ "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As Long Private Const LB_SETTABSTOPS = &H192 Public Function SetLBTabStops(LB As Object, _ ParamArray TabStops()) As Boolean 'PURPOSE: Set TabSTops for a list box 'or a UserControl based on a list box 'that exposes the underlying list boxes 'hwnd property. 'This creates columns whereby items 'in each column are separated by 'a tab character 'USAGE: 'Pass ListBox Object and a comma delimited 'list of tab stops. Tab stops are expressed 'in dialog units which approximately equal '1/4 the width of a character 'EXAMPLE: 'SetLBTabStops List1, 40, 80, 120 'List1.AddItem "Column1" & vbTab & "Column2" _ & vbTab & "Column3" & vbTab & "Column4" 'This will create 3 columns separated by 'about 10 characters Dim alTabStops() As Long Dim lCtr As Long Dim lColumns As Long Dim lRet As Long On Error GoTo errorhandler: ReDim alTabStops(UBound(TabStops)) As Long For lCtr = 0 To UBound(TabStops) alTabStops(lCtr) = TabStops(lCtr) Next lColumns = UBound(alTabStops) + 1 lRet = SendMessage(LB.hwnd, LB_SETTABSTOPS, _ lColumns, alTabStops(0)) SetLBTabStops = (lRet = 0) Exit Function errorhandler: SetLBTabStops = False End Function |
Add Columns to a List Box by Setting Tab Stops |
Express News India | Freelance ecommerce web development India