Home All Groups Group Topic Archive Search About

Listbox selected items to string array

Author
18 Oct 2006 8:17 PM
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

Author
19 Oct 2006 2:28 AM
Siva M
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.

"Colin Williams" <colinwilliams***@msn.com> wrote in message
news:1161202656.229981.117180@m73g2000cwd.googlegroups.com...
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
Author
19 Oct 2006 2:30 AM
Siva M
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.

"Colin Williams" <colinwilliams***@msn.com> wrote in message
news:1161202656.229981.117180@m73g2000cwd.googlegroups.com...
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
Author
19 Oct 2006 12:43 PM
Colin Williams
Thanks

Siva M wrote:
Show quote
> 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.
>
> "Colin Williams" <colinwilliams***@msn.com> wrote in message
> news:1161202656.229981.117180@m73g2000cwd.googlegroups.com...
> 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

AddThis Social Bookmark Button