473,503 Members | 11,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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


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
2 1559
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11249
by: headware | last post by:
I have a <select> control that contains many entries. It allows the user to multi-select a group of them, click a button, and store the selected data in a database. Normally they do this starting...
3
4652
by: Gumtree | last post by:
Hi folks, The user interface I'm trying to impliment looks a bit like this: Not Chosen Chosen .------------. .------------. |Item 1 | -> |Item 3 | |Item 2 | <-...
1
2060
by: Mad Scientist Jr | last post by:
I'm stuck trying to work with a HTML <SELECT> control and javascript (similar to DualList but that control doesn't offer enough options to totally control the text on the buttons and control, also...
1
1888
by: Chris Lieb | last post by:
In a form, I have two select lists. One holds the available options. I have some buttons between them for moving items from one list to the other. When the form first loads, all of the items are...
6
3223
by: TCook | last post by:
Hello, I was wondering if anyone has a code snippet for looping through a 'select' control's 'option' elements? Do I have to use an ASP.Net web control such as an asp list control or dropdown...
0
1157
by: TCook | last post by:
Hey All, I'm trapping a 'submit' button's 'Click' event in a VB.Net code behind class in order to loop through a 'Select' controls 'option' list as follows: For Each ThisItem In...
4
4380
by: rn5a | last post by:
A Form has 2 select lists. The 1st one whose size is 5 (meaning 5 options are shown at any given time) allows multiple selection whereas the 2nd one allows only 1 option to be selected at a time. ...
1
4009
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
25
5364
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
0
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
729
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
372
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.