A
Andreas Zita
Hello!
I have a Custom Collection which is set as datasource to a ListBox. A Form
enables moving items up and down in the list. In the collection this is
implemented like this:
public void Swap(int oldIndex, int newIndex)
{
if (newIndex >= 0 && newIndex < List.Count && newIndex != oldIndex)
{
object tmp = List[newIndex];
List[newIndex] = List[oldIndex];
List[oldIndex] = tmp;
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemMoved,
newIndex, oldIndex));
}
}
What happens now is that the listbox automatically switches positions of the
items and selects the new index (as should). The problem is that when the
event SelectedIndexChanged for the ListBox is triggered (automatically), the
SelectedItem is still the old item! How is this possible? Does the ListBox
select a new index before refreshing its datasource? ...
/AZ
I have a Custom Collection which is set as datasource to a ListBox. A Form
enables moving items up and down in the list. In the collection this is
implemented like this:
public void Swap(int oldIndex, int newIndex)
{
if (newIndex >= 0 && newIndex < List.Count && newIndex != oldIndex)
{
object tmp = List[newIndex];
List[newIndex] = List[oldIndex];
List[oldIndex] = tmp;
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemMoved,
newIndex, oldIndex));
}
}
What happens now is that the listbox automatically switches positions of the
items and selects the new index (as should). The problem is that when the
event SelectedIndexChanged for the ListBox is triggered (automatically), the
SelectedItem is still the old item! How is this possible? Does the ListBox
select a new index before refreshing its datasource? ...
/AZ