Selected Prop of List Box Can Cause Click Event & Out of StackLast reviewed: February 18, 1996Article ID: Q110957 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0
SUMMARYThe Selected property applies to list box and file list box controls. When you change the selected state of a list box item by using code to set the Selected property at run time, a Click event occurs -- just as if you had actually clicked with the mouse. A Click event does not occur if you set the item's Selected property to a value that keeps the item's current selected or unselected state. You need to take care when changing the Selected property within the Click event procedure for a list or file list box. Clicking an item in a list control causes a Click event and can change a selection. That changed selection can affect whether your code's subsequent change to an item's Selected property causes another Click event. The resulting second click event can cause recursion and "Out of Stack Space" or other errors if you designed your Click event procedure incorrectly. The More Information section below provides examples showing how to avoid recursion problems. This behavior is by design.
MORE INFORMATIONThe Selected property determines the selection status of an item in a list box or file list box control. The Selected property is an array of Boolean values with the same number of items as the List property. The Selected property is available at run time, but not at design time. Here is the syntax:
[form.]{filelistbox|listbox}.Selected(index)[ = {True|False}]The Selected property settings are:
True = The item is selected. False = (Default) The item is not selected.The Selected property is particularly useful where users can make multiple selections. You can quickly check which items in a list are selected. Your code can use this property to select or deselect items in a list. If only one item is selected, you can use the ListIndex property to get the index of the selected item. However, in a multiple selection, the ListIndex property returns the index of the item contained within the focus rectangle, whether or not the item is actually selected. Multiple selection mode can be set with the MultiSelect property.
Changing Item's Selected Property Can Cause Second Click Event
How to Make File List Box Items That Can Be Scrolled, But Not Selected
|
Additional reference words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |