Scott G

Scott G

  • NA
  • 103
  • 7.8k

How do I move multiple selections from one ListBox to another?

Jul 23 2020 10:47 AM
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).
  1. private void btnAddStat_Click(object sender, EventArgs e)  
  2. {  
  3. foreach (var item in lstStatutes.SelectedItems)  
  4. {  
  5. DataRowView drvStatute = lstStatutes.SelectedItem as DataRowView;  
  6. string stat = string.Empty;  
  7. if (drvStatute != null)  
  8. {  
  9. stat = drvStatute.Row["Statute"as string;  
  10. lstSelStatutes.Items.Add(stat);  
  11. }  
  12. }  
  13. }  

Answers (2)