Hi,
This is related to my last post.
i want to have up and down buttons on listbox items so that they can moved up/down ie changed its index in the list.
Any ideas how I would actualy do this?
Malcolm
Hi,
This is related to my last post.
i want to have up and down buttons on listbox items so that they can moved up/down ie changed its index in the list.
Any ideas how I would actualy do this?
Malcolm
I am pretty sure you can throw whatever you want into the ListBox. So you could just make your own control that has a label and two buttons for the arrows. Then throw it in the ListBox and attach the events.
I would make a button that is an up button, and in its OnClick event, do something like:
int location = listItems.SelectedIndex;
if (location > 0)
{
object rememberMe = listItems.SelectedItem;
listItems.Items.RemoveAt(location);
listItems.Items.Insert(location - 1, rememberMe);
listItems.SelectedIndex = location - 1;
}
Keep in mind this isn't tested as I don't have visual studio open right now, but it should give you a good idea.
I would include the order of the item in the model (ie. your data class). Then I'd bind the ListBox to a CollectionView
that is sorted by that value. Your up/down buttons would then simply swap the value of this sort property in two of your data items.
HTH, Kent
Are you binding it? Try to change the order of the item of the binding object and upadate the listbox.