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

Re: Listbox selected items to string array by Siva

Siva
Wed Oct 18 21:28:17 CDT 2006

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" <colinwilliams399@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


Re: Listbox selected items to string array by Siva

Siva
Wed Oct 18 21:30:11 CDT 2006

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" <colinwilliams399@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


Re: Listbox selected items to string array by Colin

Colin
Thu Oct 19 07:43:22 CDT 2006

Thanks

Siva M wrote:
> 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" <colinwilliams399@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