ListBox.SelectedItems to string array

ListBox.SelectedItems to string array

Post by Colin Will » Fri, 20 Oct 2006 05:16:26


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
 
 
 

ListBox.SelectedItems to string array

Post by Crypti » Fri, 20 Oct 2006 05:35:36

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://www.yqcomputer.com/

 
 
 

ListBox.SelectedItems to string array

Post by Colin Will » Fri, 20 Oct 2006 05:56:37

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