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

Display Items In A Collection In A Listbox

P: n/a
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
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Maria wrote:
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
Nov 13 '05 #2

P: n/a
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.*********@heuvelqop.nl> wrote in message
news:cp**********@news2.solcon.nl...
Maria wrote:
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

Nov 13 '05 #3

P: n/a
Maria wrote:
<< 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)

--
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
Nov 13 '05 #4

P: n/a
rkc
Maria wrote:
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.
Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.