|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis demo allows you to have a BackgroundHaving numeric items in a 1
10
11
12
2
3
4
5
...
To get the items to sort properly, you can write a custom sort routine which overrides the This simple demo shows two The main routine receives the source listbox and the destination listbox as parameters. It will take the selected items from the source and add them to an integer array. Next, it takes the destination listbox items and adds those to the array. Then, it calls the It's nothing fancy. And, you might want to override the Main routineHere is the code that manages the lists. This is the public void MoveNumericItemsBetweenListBoxes(ListBox SourceListBox,
ListBox DestinationListBox)
{
// Move selected items from the source list box into the destination list box.
// The destination list box will be sorted numerically.
// If no items are selected, all items are moved.
// Selected items are removed from the source list box.
// To sort items numerically, an integer array is built
// with selected items in the source list box,
// then items already in the destination list box are added to the array.
// The array is sort and the destination list box is re-populated
// create integer array for storing and sorting
int ArraySize = DestinationListBox.Items.Count +
SourceListBox.SelectedItems.Count;
if (SourceListBox.SelectedItems.Count == 0)
{
ArraySize += SourceListBox.Items.Count;
}
int[] ItemList = new int[ArraySize];
// add selected source items to array
int OnItem = 0;
if (SourceListBox.SelectedItems.Count == 0)
{
// nothing selected so copy all items
for (OnItem = 0; OnItem < SourceListBox.Items.Count; OnItem++)
{
ItemList[OnItem] = (int)SourceListBox.Items[OnItem];
}
}
else
{
// copy selected items
for (OnItem = 0; OnItem < SourceListBox.SelectedItems.Count; OnItem++)
{
ItemList[OnItem] = (int)SourceListBox.SelectedItems[OnItem];
}
}
// add current items in destination list to array
int ArrayCount = OnItem;
for (OnItem = 0; OnItem < DestinationListBox.Items.Count; OnItem++)
{
ItemList[ArrayCount++] = (int)DestinationListBox.Items[OnItem];
}
Array.Sort(ItemList);
DestinationListBox.Items.Clear();
// re-populate selected list
for (OnItem = 0; OnItem < ArraySize; OnItem++)
{
DestinationListBox.Items.Add(ItemList[OnItem]);
}
// remove selected items from source list
if (SourceListBox.SelectedItems.Count == 0)
{
SourceListBox.Items.Clear();
}
else
{
for ( önItem = SourceListBox.SelectedItems.Count - 1; OnItem >= 0; OnItem--)
{
SourceListBox.Items.RemoveAt(SourceListBox.SelectedIndices[OnItem]);
}
}
}
|
||||||||||||||||||||||