Connecting Tech Pros Worldwide Forums | Help | Site Map

List Box -- Select All Elements

Vincent
Guest
 
Posts: n/a
#1: Jul 15 '08
I have a list box that is bound to a table with many records. I
have a select all button that when clicked, obviously, selects all of
the items in the list box. However, it takes a fairly long time to
select all of the elements because I am simply looping through all of
the elements in the list box and setting the selected property to
true. I have noticed that if I perform a shift select on the list
box, all of the items are rapidly selected. Is there perhaps an API
call that can be performed to rapidly select all of the elements?
Thank you for your help.

Vincent

Rich P
Guest
 
Posts: n/a
#2: Jul 15 '08

re: List Box -- Select All Elements


Hi Vincent,

I don't know your complete scenario, so I will make one up: you have a
listbox on a form and a subform below that in datasheet view. You
select something from the listbox and records will display in the
subform based on the selection from the listbox. Then you have a
"Select All" button. The goal of the "Select All" button is to display
all the records that are related to the Params in the Listbox. If this
is your scenario (or something like it) how about when you click on the
"Select All" button you just bypass the Listbox and do something like

Private Sub cmdSelectAll_Click()
Subform.Recordsource = "Select * from tblX Where someParamField in
(Select * from tbl_thatIsListboxSource)"
Me.Requery
End Sub

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Vincent
Guest
 
Posts: n/a
#3: Jul 15 '08

re: List Box -- Select All Elements


On Jul 15, 1:02*pm, Rich P <rpng...@aol.comwrote:
Quote:
Hi Vincent,
>
I don't know your complete scenario, so I will make one up: *you have a
listbox on a form and a subform below that in datasheet view. *You
select something from the listbox and records will display in the
subform based on the selection from the listbox. *Then you have a
"Select All" button. *The goal of the "Select All" button is to display
all the records that are related to the Params in the Listbox. *If this
is your scenario (or something like it) how about when you click on the
"Select All" button you just bypass the Listbox and do something like
>
Private Sub cmdSelectAll_Click()
Subform.Recordsource = "Select * from tblX Where someParamField in
(Select * from tbl_thatIsListboxSource)"
Me.Requery
End Sub
>
Rich
>
*** Sent via Developersdexhttp://www.developersdex.com***
Rich,

No, you misunderstood me. I am not selecting data to bind to my
listbox. I am trying to rapidly select all of the elements already in
the listbox. It is currently being done as follows:

Dim i as integer

for i = 0 to myListBox.count -1
myListBox.selected(i) = true
next

This is a rather long loop considering how many elements I have
in my list box. I want to shorten the time it takes to select all of
the elements. Thanks.

Vincent
Rich P
Guest
 
Posts: n/a
#4: Jul 15 '08

re: List Box -- Select All Elements


That I can think of, the loop is the only method of selecting items from
the listbox. I am curious what the objective is after you have selected
all of the elements. I picture a listbox with say 5000 items - all
selected now. What happens after that? Why not just select the items
directly from the datasource table? Note: If you have more than a few
dozen items displayed in a listbox at a time - you may want to rethink
your logic.

Usually, a listbox will be populated with a subset of data from a
dataset. A listbox is usually a filtered list from a dataset. Here is
a rule of thumb for RDBMS programming - if a single process (if you call
a procedure in a loop 1000 times - that is 1000 processes) is taking
more than a few seconds - it is time to rethink the logic.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Salad
Guest
 
Posts: n/a
#5: Jul 15 '08

re: List Box -- Select All Elements


Rich P wrote:
Quote:
That I can think of, the loop is the only method of selecting items from
the listbox. I am curious what the objective is after you have selected
all of the elements. I picture a listbox with say 5000 items - all
selected now. What happens after that? Why not just select the items
directly from the datasource table? Note: If you have more than a few
dozen items displayed in a listbox at a time - you may want to rethink
your logic.
>
Usually, a listbox will be populated with a subset of data from a
dataset. A listbox is usually a filtered list from a dataset. Here is
a rule of thumb for RDBMS programming - if a single process (if you call
a procedure in a loop 1000 times - that is 1000 processes) is taking
more than a few seconds - it is time to rethink the logic.
>
Rich
>
*** Sent via Developersdex http://www.developersdex.com ***
I was using a listbox with a Table/Query rowsource type. Due to the
complexity of the query it placed a drag on the form when I'd open the
form or refresh the data. I did various kludges with some improvement
here and there...then I decided to design a rowsource type as a
user-defined function. Doing so made my listbox(s) get a real energy
boost! It went from Drag to NoDrag.

I'm not a fan of large combos or listboxes. It overwhelms the vertical
scroll bars and is a pita for finding data using Table/Query rowsource
types. In the case of the OP I would suggest he look for the help topic
"RowSourceType Property (User-Defined Function) — Code Argument Values"
in Access help and if he/she's a worthy programmer and can follow
instructions/example then try it out and see if that gives a boost to
the process. I'll guess as to why it's faster...instead of disk based
retrieval of records the data in the list box is in memory.

SuperStar
http://www.youtube.com/watch?v=J_3zRh6HeZs
Closed Thread