Connecting Tech Pros Worldwide Help | Site Map

Display Items In A Collection In A Listbox

  #1  
Old November 13th, 2005, 06:22 AM
Maria
Guest
 
Posts: 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


  #2  
Old November 13th, 2005, 06:22 AM
Bas Cost Budde
Guest
 
Posts: n/a

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
  #3  
Old November 13th, 2005, 06:22 AM
Maria
Guest
 
Posts: n/a

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]


  #4  
Old November 13th, 2005, 06:23 AM
Bas Cost Budde
Guest
 
Posts: n/a

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
  #5  
Old November 13th, 2005, 07:18 AM
rkc
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Expose Count from System.Collections.CollectionBase in an inherited class GoCoogs answers 2 July 20th, 2006 07:45 PM
Listbox slows down when adding large number of items Paul_Madden via DotNetMonster.com answers 14 June 14th, 2006 07:45 PM
Hover over items in ListBox Phil Kelly answers 1 November 20th, 2005 11:27 PM
Mixing DataSource and a Collection in ListBox AI_Is_My_Thing answers 0 November 16th, 2005 03:58 PM