How to Pre-Select items in a Multi-select listbox????

How to Pre-Select items in a Multi-select listbox????

Anonymous
Not applicable
272 Views
2 Replies
Message 1 of 3

How to Pre-Select items in a Multi-select listbox????

Anonymous
Not applicable
I have code that "Should" upon loading the form check to see if toolbars are
loaded:

'cycle through the toolbars and add the appropriate menus to the lisbox
For Each objToolBar In objMenuGroup.Toolbars
strToolbarID = objToolBar.TagString
strCompare = Mid(strToolbarID, 1, IDLength)
If strCompare = strID Then
strToolbarName = objToolBar.Name
ListBox1.AddItem (strToolbarName)
Set objToolBar = objMenuGroup.Toolbars(strToolbarName)
If objToolBar.Visible = True Then
ListBox1.Selected(strToolbarName) = True
End If
Else
MsgBox "something is wrong"
End If
Next

Except no actual item in the multi - select listbox gets selected. How do i
select something through code.
0 Likes
273 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
> Except no actual item in the multi - select listbox gets
> selected. How do i select something through code.

You need the index number of a list item, not the actual
text string, in order to select it. One way is to cycle
through the list looking for a match:

For i = 0 To Lisbox1.ListCount - 1
If strToolbarID = Listbox1.List(i) Then
Listbox1.Selected(i) = True
Exit For
End If
Next

--
http://www.acadx.com
0 Likes
Message 3 of 3

Anonymous
Not applicable
Try:

ListBox1.Selected(ListBox1.ListCount-1) = True

The Selected property expects an integer index value corresponding to the
item's position in the list. Since you're adding the items to the listbox,
the 'current' item would be the last item added.

Patrick Porter wrote in message
news:649CCD51C742DBE6B057D050802126AC@in.WebX.maYIadrTaRb...
> I have code that "Should" upon loading the form check to see if toolbars
are
> loaded:
>
> 'cycle through the toolbars and add the appropriate menus to the lisbox
> For Each objToolBar In objMenuGroup.Toolbars
> strToolbarID = objToolBar.TagString
> strCompare = Mid(strToolbarID, 1, IDLength)
> If strCompare = strID Then
> strToolbarName = objToolBar.Name
> ListBox1.AddItem (strToolbarName)
> Set objToolBar = objMenuGroup.Toolbars(strToolbarName)
> If objToolBar.Visible = True Then
> ListBox1.Selected(strToolbarName) = True
> End If
> Else
> MsgBox "something is wrong"
> End If
> Next
>
> Except no actual item in the multi - select listbox gets selected. How do
i
> select something through code.
>
>
0 Likes