Hastable/SortedList->Combobox

  • Thread starter Thread starter nevin
  • Start date Start date
N

nevin

Hello all,

I've looked on the net and can't seem to find what I need so I must be
searching badly or have (another) 'non-problem'.
I am simply trying to move the values of a hastable or sorted list into a
combobox control. I'm willing to lose the key item of the collection I just
need the values.
Surely i don't need to enumerate the entire collection adn add the values
one by one into the combobox?

Thanks
Nev
 
nevin said:
Hello all,

I've looked on the net and can't seem to find what I need so I must be
searching badly or have (another) 'non-problem'.
I am simply trying to move the values of a hastable or sorted list into a
combobox control. I'm willing to lose the key item of the collection I just
need the values.
Surely i don't need to enumerate the entire collection adn add the values
one by one into the combobox?

Thanks
Nev

http://samples.gotdotnet.com/quicks...Binding.src&file=CS\ComboBoxBinding.cs&font=3

(URL will be word-wrapped)

Erik
 
Since ComboBox.Items is of the class ComboBox.ObjectCollection you can
use its AddRange(object[]) method to quickly add all the items. You
might have to use ICollection.CopyTo() to get them from the hashtable in
to an Object[], although I seem to remember an easier way, I just can't
find it at the moment.

I hope that helps!
DC
 
The way I ended up doing it was:

combo.DataSource=sortedlist.GetValueList();

Thanks to Eric and DC for the pointers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top