storage selected listbox items into a new array
asp.net, c#
Solution
Your code won't work because index i is not used to indicate `SelectedIndices`, but `Items`.
So update it:
string[] domains = new string[listBox1.SelectedIndices.Count];
for (int i = 0; i < listBox1.SelectedIndices.Count; i++)
{
domains[i] = listBox.Items[listBox1.SelectedIndices[i]].ToString();
}
What I prefer:
List<string> domains = new List<string>();
for (int i = 0; i < listBox1.SelectedIndices.Count; i++)
{
domains.Add(listBox.Items[listBox1.SelectedIndices[i]].ToString());
}
Problem
How can I store the selected item(s) in a `listbox` to a new array? Like we select the items and then do the button's action, e.g. ``` string[] domains = new string[listBox1.Items.Count]; for (int i = 0; i < listBox1.Items.Count; i++) { domains[i] = listBox1.SelectedIndices[i].ToString(); } ```