Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiselect property of a listbox 2

Status
Not open for further replies.

pankajv

Programmer
Jan 30, 2002
178
IN
I have couple of questions regarding the listbox which has the multiselect property = true
1. How do I access all the selected items in the list box.
2. Assume that an item is already selected. Now the user presses the shift key and then click on an item. I should be able to select all the items between the 2 items.

Some sample code will be of great help.

 
I notice that even after asking over 70 questions on the forum, you don't seem to have said 'Thanks' very often, and you haven't marked a single post as being helpful.

That being said, the answer to your answer is probably in VBHelp, under ListBox control (which is where I usually start)

what I would do is:

1. Loop through the List, looking for Selected = True

For a = 0 To List1.ListCount - 1
If List1.Selected(a) = True Then
Debug.Print List1.List(a)
End If
Next a

2. Set Multiselect to Extended


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
MultiSelect is not a Boolean property. It is an Integer with three settings.

vbMultiSelectNone = 0 (default)
vbMultiSelectSimple = 1
vbMultiSelectExtended = 2

First about your second question.
The list box you need requires the MultiSelect property set to vbMultiSelectExtended.

Now the first question - How to access all the selected items?
The answer is the Seleted() array of list box object.
This array is a Boolean array which tells the selected status of an item in the list.

You may write your code like this.

Dim L As Long
For L = 0 To List1.ListCount - 1
If List1.Selected(L) Then
'The item is selected
Else
'The item is not selected
End If
Next
 
Hypetia
Snap!
[smile]


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
It worked like charm. Thanks for all the help. I future I will try to post the thanks regularly.
 
Johnwm & Hypetia ..
You guys are too quick for someone still learning to figure out the answers and post it. I just got it working right, came back here ... and there are 2 answers!
Stars for each of ya

John,
Just so you know, VBHelp is really lacking on using this control.No examples or property explanations. :-(
Michael
 
I kept my old MSDN disks (April 01) for use in VB. However there is still quite a lot of VB6 stuff on MSDN online. For example a search on MSDN for 'listbox control multiselect vb' gave me (amongst others):




________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top