Microsoft KB Archive/142928

= PRB: Bound ListBox Doesn't Show List Item When MultiSelect = 2 =

Article ID: 142928

Article Last Modified on 5/7/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Enterprise Edition

-



This article was previously published under Q142928



SYMPTOMS
If you set the MultiSelect property of a bound Standard ListBox control at design time to 2-Extended, and then run the application, you can MultiSelect with CTRL+Click but the control is not bound to the Data control at this time. When you go back into design mode, the MultiSelect property is reset to 0-None, then when you run again, you get the correct behavior.



CAUSE
This is a behavior of Visual Basic. It is not practical to select multiple items from a listbox that is bound to only a single column of a data control. If you set the MultiSelect property of the control to 2-Extended, Visual Basic should reset it back to 0-None before going into run mode, not after it returns from the first run. This way it will not appear that you can almost get MultiSelect to work with a bound listbox.



RESOLUTION
Do not set the MultiSelect Property of a bound standard ListBox control to 2-Extended as it will cause this misleading behavior.



Steps to Reproduce Problem in Visual Basic Version 4.0
 Start a new project in Visual Basic. Form1 is created by default. Add a Data control to Form1. Connect Data1 on Form1 to a table in a database as follows: Select the Data control and press the F4 key to display the Properties window. Set the DatabaseName property to BIBLIO.MDB, and set the RecordSource property to the source table name Publishers. Add a Standard ListBox control to Form1. Select the ListBox control and press the F4 key to display the Properties window. Set the DataSource property to Data1, the DataField property to State, and the MultiSelect property to 2-Extended.  Add the following to the Form Load event code: Private Sub Form_Load List1.AddItem "CA" List1.AddItem "WA" List1.AddItem "PA" List1.AddItem "MA" List1.AddItem "IL" List1.AddItem "FL" End Sub  Start the program, or press the F5 key. Click next and previous on the data control and notice how the selection on the listbox does not change even though it is bound to the Data control. You can MultiSelect with CTRL+Click. When you go back into design mode the MultiSelect property is reset to 0-None, then when you run again, you get the correct behavior.</li></ol>

Additional query words: kbVBp400 kbVBp600 kbdse kbDSupport kbVBp kbControl

Keywords: kbprb KB142928

-

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

© Microsoft Corporation. All rights reserved.