I have a listbox which contains 20-50 items. All items must be sorted by unique id.
After applying sort, my listbox scrolls at top. How to prevent that?
Sort function
public static void Sort<TSource, TValue>(IList<TSource> source, Func<TSource, TValue> selector) {
for (int i = source.Count - 1; i >= 0; i--) {
for (int j = 1; j <= i; j++) {
TSource o1 = source.ElementAt(j - 1);
TSource o2 = source.ElementAt(j);
TValue x = selector(o1);
TValue y = selector(o2);
var comparer = Comparer<TValue>.Default;
if (comparer.Compare(x, y) > 0) {
source.Remove(o1);
source.Insert(j, o1);
}
}
}
}
Only this helped