By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

how can i 'select' items in a list box from a button click

P: n/a

Hello all,

I have a listbox with 2 'fields' and a choice of 100 or so items that
can be selected.

User can select multiple items (i'm using the simple multiitem model) as
normal.

however, I want several buttons that will select a set of these items if
pressed.

the pseudo code i would use is as follows, but I don't know the VBA to
use - any help appreciated.

eg:
listbox name: SourceList
2 columns: Source_ID and Description
100+ different Source_ID's in the list

list1 has 10 Source_ID's in it
list2 has a different 10 etc

pseudo code:

for each item in the listbox
if the item value is in list1 (or list2 etc)
then make that item 'selected'
else leave it unselected
next

I can CLEAR a listbox no problem using the code:

For Each varItem In SourceList.ItemsSelected
SourceList.Selected(varItem) = False
Next varItem

and I understand how that works, but I cant figure out how to do it the
other way round...

any help appreciated.

andy warner
*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Somthing like this:

For varloop = 1 To Me.LstOrders.ListCount
Me.LstOrders.Selected(varloop) = False
If Me.LstOrders.Column(1, varloop) = 'Your criteria' Then
Me.LstOrders.Selected(varloop) = True
End If
Next varloop

Filip

"Andy Warner" <aw*****@worcestershire.gov.uk> wrote in message
news:e1***************@news.uswest.net...

Hello all,

I have a listbox with 2 'fields' and a choice of 100 or so items that
can be selected.

User can select multiple items (i'm using the simple multiitem model) as
normal.

however, I want several buttons that will select a set of these items if
pressed.

the pseudo code i would use is as follows, but I don't know the VBA to
use - any help appreciated.

eg:
listbox name: SourceList
2 columns: Source_ID and Description
100+ different Source_ID's in the list

list1 has 10 Source_ID's in it
list2 has a different 10 etc

pseudo code:

for each item in the listbox
if the item value is in list1 (or list2 etc)
then make that item 'selected'
else leave it unselected
next

I can CLEAR a listbox no problem using the code:

For Each varItem In SourceList.ItemsSelected
SourceList.Selected(varItem) = False
Next varItem

and I understand how that works, but I cant figure out how to do it the
other way round...

any help appreciated.

andy warner
*** Sent via Developersdex http://www.developersdex.com ***

Nov 13 '05 #2

P: n/a
AH-HA!!

got it! thanks. I kinda tried it, but didnt get the 'column' bit.

cheers
andy

*** Sent via Developersdex http://www.developersdex.com ***
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.