Databound Listbox SelectedItem
I have a listbox bound to a datasource, which gets updated.
When it does the selected index remains the same. Meaning, that the selected item is different, since the order/number of items could change as the datasource is updated.
Is there any way round this?
Re: Databound Listbox SelectedItem
Exactly what is the control bound to? Can you provide some example code we can execute to demonstrate the issue?
Re: Databound Listbox SelectedItem
It's bound to a class derived from BindingList of custom objects, which only every has items added or removed (the list isn't cleared and repopulated).
All i did was add AddRange / RemoveRange functions as below:
Code:
public void AddRange(IEnumerable<T> Items, IEqualityComparer<T> Comparer)
{
foreach (T Item in Items)
{
if (!this.Items.Contains(Item, Comparer))
this.Items.Add(Item);
}
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, 0));
}
I may have answered my own question. Is this issue caused by me using the Reset listchangedtype enumeration value?
I used that figuring no others were appropriate since it wasn't just one index that was changing.