I have two listboxes. The first is populated from an SQL table. I am trying to allow the user to select mutiple entried from the first box and move them to the second. I tried using the code below (which works fine when selecting a single item from the listbox) in the loop but it still selects only the first item and adds it for each selection I make. (ie. If I select statute 12345, 12346 and 12347 it adds 12345 3 times to the other listbox).
- private void btnAddStat_Click(object sender, EventArgs e)
- {
- foreach (var item in lstStatutes.SelectedItems)
- {
- DataRowView drvStatute = lstStatutes.SelectedItem as DataRowView;
- string stat = string.Empty;
- if (drvStatute != null)
- {
- stat = drvStatute.Row["Statute"] as string;
- lstSelStatutes.Items.Add(stat);
- }
- }
- }