Click to See Complete Forum and Search --> : Swaping Listbox items


kohlimannu
October 1st, 2005, 07:48 AM
How to swap listbox items

like if i press down button (command buttn) my selected item move one item down if i press up button then its move one item up.

jmcilhinney
October 1st, 2005, 08:52 AM
Store the SelectedItem in a variable, Remove it from the ListBox, Insert it at the desired index, then assign it to the SelectedItem property again. To move down:int currentIndex = myListBox.SelectedIndex;
Object selectedItem = myListBox.SelectedItem;

myListBox.Items.Remove(selectedItem);
myListBox.Items.Insert(++currentIndex, selectedItem);
myListBox.SelectedItem = selectedItem;

kohlimannu
October 3rd, 2005, 12:45 AM
Store the SelectedItem in a variable, Remove it from the ListBox, Insert it at the desired index, then assign it to the SelectedItem property again. To move down:int currentIndex = myListBox.SelectedIndex;
Object selectedItem = myListBox.SelectedItem;

myListBox.Items.Remove(selectedItem);
myListBox.Items.Insert(++currentIndex, selectedItem);
myListBox.SelectedItem = selectedItem;
thnx alot dear its works