Skip to content

Instantly share code, notes, and snippets.

@derans
Created March 12, 2012 05:41
Show Gist options
  • Save derans/2020077 to your computer and use it in GitHub Desktop.
Save derans/2020077 to your computer and use it in GitHub Desktop.
Move Items Old School
protected void moveItems(ListControl sendingLB, ListControl receivingLB)
{
ListBox temp = new ListBox();
List<ListItem> tempList = new List<ListItem>();
Comparison<ListItem> compare = new Comparison<ListItem>(CompareListItems);
foreach (ListItem li in sendingLB.Items)
if (li.Selected && receivingLB.Items.FindByText(li.Text) == null)
receivingLB.Items.Add(li);
else
temp.Items.Add(li);
foreach (ListItem li in receivingLB.Items)
tempList.Add(li);
tempList.Sort(compare);
receivingLB.Items.Clear();
receivingLB.Items.AddRange(tempList.ToArray());
sendingLB.Items.Clear();
foreach (ListItem li in temp.Items)
sendingLB.Items.Add(li);
receivingLB.ClearSelection();
}
int CompareListItems(ListItem li1, ListItem li2)
{
return String.Compare(li1.Text, li2.Text);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment