ListBox.SelectedItems to string array

C

Colin Williams

Hi
I am trying to pass the selected items from a multiselect listbox to a
string array. Can any body give me a start.
Thanks

Colin Williams
 
C

Cryptik

Try this:

listBox1.Items.Add("this");
listBox1.Items.Add("is");
listBox1.Items.Add("a");
listBox1.Items.Add("test");

string[] destination = new string[listBox1.Items.Count];

listBox1.Items.CopyTo(destination, 0);

That example uses the Items collection but the SelectedItems collection
work work just the same, it's the CopyTo function you should be looking
at.


Kelly S. Elias
Webmaster
http://devdistrict.com
 
C

Colin Williams

Thanks
Had the code there but commented out! Must have threw inadvertent
errors. Code blindness perhaps.
Thanks once again

Try this:

listBox1.Items.Add("this");
listBox1.Items.Add("is");
listBox1.Items.Add("a");
listBox1.Items.Add("test");

string[] destination = new string[listBox1.Items.Count];

listBox1.Items.CopyTo(destination, 0);

That example uses the Items collection but the SelectedItems collection
work work just the same, it's the CopyTo function you should be looking
at.


Kelly S. Elias
Webmaster
http://devdistrict.com


Colin said:
Hi
I am trying to pass the selected items from a multiselect listbox to a
string array. Can any body give me a start.
Thanks

Colin Williams
 

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

Top