Display Items In A Collection In A Listbox

  • Thread starter Thread starter Maria
  • Start date Start date
M

Maria

How can I display the items in a collection in a listbox? Then, what is the
code to remove an item from the collection when the item is selected in the
listbox ?

Thanks for all help!!

Maria
 
Maria said:
How can I display the items in a collection in a listbox? Then, what is the
code to remove an item from the collection when the item is selected in the
listbox ?

set the RowsourceType property of the listbox to "value list". Have a
function that takes a Collection and returns its members in a properly
separated string; assign that to the RowSource property of the listbox

If you are sure you want to do this on click (when the user navigates
with the keyboard, the Click fires for every row passed, which I
wouldn't expect):

Set the onClick property for the listbox to [Event Procedure] and write
an event handler that removes the item from the collection. Re-filling
the list is an option.
 
First of all you should have a table with two fields at least "Item" text and
"Picked" Yes/No.
Then enter some names for example:

Fanta
Coke
Sprite

Then lookup this table in the list box you want by adding a list box in a
form the clicking on the properties then

Row Source Type: Table/Query
Row Source: Click on the small button and select the items table and add
both columns (item and picked) in the criteria under picked type 0, meaning
that it should display only unpicked items and close the query window

Also, set other properties like number of columns (1), limit to list (yes)
etc.

Now you need a coding that whenever you double click on an item it should be
picked and then a requery method should be applied. If could follow upto
hear, let me do the rest for you in the next episode.

Zubair
 
Dear Maria:
If your question is still not answered, let me know so that i can explain
you and send you an example.

In short, you need a column (selected or picked) with yes/no data type in
the item list, you need in the list box to filter it by this field (selected
or picked criteria 0).
Then a query to make this box checked or unchecked (-1, 0) when you
double-click or click and then a requery method to refresh the list.

Zubair
 
Thank you for responding!

How do I do the following ---

<< function that takes a Collection and returns its members in a properly
separated string; >>

<< event handler that removes the item from the collection. Re-filling the
list is an option.>>

Maria

Bas Cost Budde said:
Maria said:
How can I display the items in a collection in a listbox? Then, what is the
code to remove an item from the collection when the item is selected in the
listbox ?

set the RowsourceType property of the listbox to "value list". Have a
function that takes a Collection and returns its members in a properly
separated string; assign that to the RowSource property of the listbox

If you are sure you want to do this on click (when the user navigates
with the keyboard, the Click fires for every row passed, which I
wouldn't expect):

Set the onClick property for the listbox to [Event Procedure] and write
an event handler that removes the item from the collection. Re-filling
the list is an option.

--
Bas Cost Budde, Holland
http://www.heuveltop.nl/BasCB/msac_index.html
I prefer human mail above automated so in my address
replace the queue with a tea
 
Maria said:
<< function that takes a Collection and returns its members in a properly
separated string; >>

It does depend a bit on what exactly is in the Collection.

Air code:

function EnumColl(coll as collection)as string
dim item as variant
dim cRes as string
for each item in collection
cres=cres & item.value & ";"
next
enumcoll=left(cres,len(cres)-1)
end function
<< event handler that removes the item from the collection. Re-filling the
list is an option.>>

Form is open in design view? Good. Select the listbox, view Properties,
tab Events; choose [Event Procedure] for onClick.
Click the three dot button. If you are presented with three options,
choose the one similar to "write code" (what was that again?)

Put this inside:

yourcollection.remove yourlistbox.listindex

If it doesn't remove the right one, you might have to put

yourcollection.remove yourlistbox.listindex +1

the optional part is then
yourlistbox.rowsource = enumcoll(yourcollection)
 
Maria said:
How can I display the items in a collection in a listbox? Then, what is the
code to remove an item from the collection when the item is selected in the
listbox ?

Thanks for all help!!

Maria

Look at the RowSourceType Property in help via the Visual Basic IDE.
While your at it, look at the members of VBA.Collection in the Object
Browser which is available from the View menu of the IDE.
 
Back
Top