Created
March 12, 2012 05:41
-
-
Save derans/2020077 to your computer and use it in GitHub Desktop.
Move Items Old School
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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