Microsoft KB Archive/183518

= PRB: Cannot Set TabStops in ListBox Using SendMessage API =

Article ID: 183518

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q183518



SYMPTOMS
When you use the SendMessage API and the LB_SETTABSTOPS message to define custom TabStops within a ListBox control to give the appearance of multiple columns, there is no effect on a ListBox control whose Style property is set to "1 - Checkbox."



CAUSE
To set the columns in the ListBox, send the ListBox control a LB_SETTABSTOPS message along with information to define the TabStops. A list box must be created with the LBS_USETABSTOPS style to respond to this message. The Visual Basic ListBox with a style set to "1 - Checkbox" is not created with the LBS_USETABSTOPS style. Therefore, the LB_SETTABSTOPS message has no effect on the ListBox control.



RESOLUTION
To set custom TabStops within the standard Visual Basic ListBox control, you must set the style setting to "0 [ASCII 150] Standard." Alternatives include using controls provided by third-party vendors, or using the Microsoft Grid or ListView controls to obtain the look and functionality you desire.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Create a new Standard EXE project. Add a command button to Form1. Add a ListBox control to Form1.  Paste the following code into Form1's code window: 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

Private Sub Command1_Click Dim ListBoxTabs(2) As Long Dim result As Long

'Set the tab stop points. ListBoxTabs(1) = 75 ListBoxTabs(2) = 200

'Send LB_SETTABSTOPS message to ListBox. result = SendMessage(List1.hWnd, LB_SETTABSTOPS, _                              UBound(ListBoxTabs) + 1, _                               ListBoxTabs(1))

'Refresh the ListBox control. List1.Refresh End Sub

Private Sub Form_Load 'Add a few items to the ListBox. List1.AddItem "January Sales" & vbTab & _ "February Sales" & vbTab & _ "March Sales" List1.AddItem "50" & vbTab & _ "500" & vbTab & _ "5000"     End Sub

 Save and run the project.</li> Click Command1.

RESULT: Two TabStops are set in the ListBox control. The first is 75 twips and the second is 200 twips.</li> Stop the application.</li> Set the Style property of the ListBox control to "1 [ASCII 150] Checkbox."</li> Repeat steps 5 and 6.

RESULT: The TabStops do not affect the ListBox control.</li></ol>

Additional query words: list box check box kbVBp500 kbVBp600 kbControl kbWin32SDK kbAPI kbVBp kbdsd kbDSupport

Keywords: kbprb kbgrpdsvb KB183518

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.