| Create a multi-column lisbox using tabs! Assumes:'NOTES: Before calling, you must fill the TabStop array with the number of tab stops desired EXAMPLE:To Call: Dim mystring As String ReDim Preserve TabStop(0) TabStop(0) = 10 ReDim Preserve TabStop(1) TabStop(1) = 20 ReDim Preserve TabStop(2) TabStop(2) = 30 mystring = Text1 & Chr$(9) & Text2 & Chr$(9) & Text3 & Chr$(9) & Text4 Call AddItemCol(List1, mystring, TabStop) '------------------------------------------------------- API ----------------------------------------------------------------- If Win16 Then Private Declare Function GetFocus Lib "User" Alias "Getfocus" () As Integer Private Declare Function GetDialogBaseUnits Lib "User" () As Long Private Declare Sub SendMessage Lib "User" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) Private Declare Sub SetFocusAPI Lib "User" Alias "SetFocus" (ByVal hwnd As Integer) #Else Private Declare Function GetFocus Lib "user32" () As Long Private Declare Function GetDialogBaseUnits Lib "user32" () As Long 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 Declare Function SetFocusAPI Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long #End If Const WM_USER = &H400 Const LB_SETTABSTOPS = WM_USER + 19 Public TabStop() As Integer '------------------------------------------------------------------------------------------------------------ Attribute VB_Name = "MODaddListCol" Public Function AddItemCol(ByVal cListBox As Control, sItem2Add As String, vTabStopArray As Variant) As Boolean AddItemCol = True Dim OldHandle As Long Dim ListHandle As Long Dim DlgWidthUnits As Long Dim I As Integer 'Get Handle of original active control OldHandle = GetFocus() 'Set focus to ListBox cListBox.SetFocus 'Get the handle of the listbox ListHandle = GetFocus() 'Get the Dialog Width Units DlgWidthUnits = (GetDialogBaseUnits() Mod 65536) / 2 'Calculate tab stops For I = 0 To UBound(vTabStopArray) TabStop(I) = TabStop(I) * DlgWidthUnits Next I 'set tab stops Call SendMessage(ListHandle, LB_SETTABSTOPS, UBound(vTabStopArray), TabStop(0)) 'Set focus back to original active control Call SetFocusAPI(OldHandle) 'Add the item to the listbox cListBox.AddItem sItem2Add End Function |
Create a multi-column lisbox using tabs |
Express News India | Freelance ecommerce web development India