Connecting Tech Pros Worldwide Help | Site Map

Display Items In A Collection In A Listbox

Maria
Guest
 
Posts: n/a
#1: Nov 13 '05
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


Bas Cost Budde
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Display Items In A Collection In A Listbox


Maria wrote:[color=blue]
> 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 ?[/color]

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
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Display Items In A Collection In A Listbox


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" <b.costbudde@heuvelqop.nl> wrote in message
news:cpordj$d5u$1@news2.solcon.nl...[color=blue]
> Maria wrote:[color=green]
> > How can I display the items in a collection in a listbox? Then, what is[/color][/color]
the[color=blue][color=green]
> > code to remove an item from the collection when the item is selected in[/color][/color]
the[color=blue][color=green]
> > listbox ?[/color]
>
> 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[/color]


Bas Cost Budde
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Display Items In A Collection In A Listbox


Maria wrote:[color=blue]
> << function that takes a Collection and returns its members in a properly
> separated string; >>[/color]

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
[color=blue]
> << event handler that removes the item from the collection. Re-filling the
> list is an option.>>[/color]

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)

--
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
rkc
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Display Items In A Collection In A Listbox


Maria wrote:[color=blue]
> 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[/color]

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.


Closed Thread