Listbox selected items to string array

  • Thread starter Thread starter Colin Williams
  • Start date Start date
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
 
Assuming you are talking about ListBox ASP.NET Control:

ArrayList al = new ArrayList ();
foreach (ListItem li in ListBox1.Items)
{
if (li.Selected) al.Add (li.Value);
}
String[] s = (string[])al.ToArray (typeof (string));

Array "s" will have the strings selected from the ListBox.

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
 
Sorry, forgot to add: in case of Windows Forms ListBox, loop through
SelectedItems or SelectedIndices to fetch each selected item's text and add
it to an ArrayList and finally convert it to String array as shown in my
previous post.

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
 
Back
Top