AUTOselect LIST BOX

Sanchez

OSNN Junior Addict
Joined
8 Jun 2004
Messages
14
When the form is opened I want the first item in the list box to be selected and highlighted...you can do this with a combo box but what would I need to type (Under Private Sub Form_Open) to do this with a list box??

THANKS
 
Selected Property
See Also Example Applies To

Returns or sets the selection status of an item in a FileListBox or ListBox control. This property is an array of Boolean values with the same number of items as the List property. Not available at design time.

Syntax

object.Selected(index) [= boolean]

The Selected property syntax has these parts:

Part Description
Object An object expression that evaluates to an object in the Applies To list.
Index The index number of the item in the control.
Boolean A Boolean expression specifying whether the item is selected, as described in Settings.


Settings

The settings for boolean are:

Setting Description
True The item is selected.
False (Default) The item isn't selected.


Remarks

This property is particularly useful when users can make multiple selections. You can quickly check which items in a list are selected. You can also use this property to select or deselect items in a list from code.

If the MultiSelect property is set to 0, 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.

If a ListBox controls Style property is set to 1 (check boxes), the Selected property returns True only for those items whose check boxes are selected. The Selected property will not return True for those items which are only highlighted.
 
When I put this code in Form_Open:

Me("ListBox").Selected(0) = True

It does select the first item..however, after I cannot switch the selected item...everything just gets locked.
 
Everything?

Me("ListBox").Selected(0) = True

Is this your naming standard or just an example? It might be getting confused because you have a string variable in the array index variable.

ListBox1(index).selected(index) = True 'index needs to be an integer or a variable containing an integer.

A site I like to use as reference is MSDN.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,623
Latest member
AndersonLo
Back