2
Every time I move an item up or down a listBox
he loses focus of the item.
I’m not always able to focus on the item.
For example, let’s assume my list has 200 items. Then I want to move the item that is in position 160 to 159, as soon as moved it loses the selection (focus) of it, in case you want to move from 159 to 158 I will have to click again on the item and select.
public void MoveItem(int direction)
{
if (listBox.SelectedItem == null || listBox.SelectedIndex < 0)
return;
int newIndex = listBox.SelectedIndex + direction;
if (newIndex < 0 || newIndex >= listBox.Items.Count)
return;
object selected = listBox.SelectedItem;
listBox.Items.Remove(selected);
listBox.Items.Insert(newIndex, selected);
}
I have tried this logic, but it also did not work, he if he wants to selected some item from Listbox, debugging it passes the right value..
– Verin
Did you do this inside the Moveitem() or outside method? Try to put after the method execution.
– perozzo
I’ve tried it in and out.
– Verin