I made a test with SortChaging and SortChaged events and did not find any issues with the position of the BindingSource. Here is the sample application used:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public class MojTip
{
public string Ime { get; set; }
public string Priimek { get; set; }
public string Naslov { get; set; }
public int Starost { get; set; }
public int Cnt { get; set; }
public MojTip() { }
}
private Random m_Random;
private List<MojTip> m_TestniPodatki;
public void PoljubenTip()
{
m_TestniPodatki = new List<MojTip>();
for (int i = 0; i < 100; i++)
{
MojTip item = new MojTip()
{
Ime = GetRandomIme(),
Priimek = GetRandomPriimek(),
Starost = GetRandomStarost(),
Cnt=i
};
m_TestniPodatki.Add(item);
}
}
#region RandomFunctions
private string GetRandomIme()
{
string[] strImena = { "Adam", "Marko", "Mitja", "Peter", "Miha", "Matjaž", "Emir", "Emil", "Franjo", "Amos" };
return strImena[m_Random.Next(0, strImena.Length)];
}
private string GetRandomPriimek()
{
string[] strImena = { "Novak", "Horvat", "Tron", "Trom", "Linden", "Osper", "Gröyk", "How", "To", "Select", "Another", "Random", "Value", "NoIdea", "Tester" };
return strImena[m_Random.Next(0, strImena.Length)];
}
private int GetRandomStarost()
{
return m_Random.Next(8, 40);
}
#endregion
public Form1()
{
m_Random = new Random();
InitializeComponent();
PoljubenTip();
bindingSource1.DataSource = m_TestniPodatki;
bindingSource1.PositionChanged += new EventHandler(bindingSource1_PositionChanged);
radGridView1.SortChanging += new Telerik.WinControls.UI.GridViewCollectionChangingEventHandler(radGridView1_SortChanging);
radGridView1.SortChanged += new Telerik.WinControls.UI.GridViewCollectionChangedEventHandler(radGridView1_SortChanged);
}
void bindingSource1_PositionChanged(object sender, EventArgs e)
{
this.label1.Text = string.Format("Current pos: {0}", this.bindingSource1.Position);
}
private int rowIndex = -1;
void radGridView1_SortChanging(object sender, Telerik.WinControls.UI.GridViewCollectionChangingEventArgs e)
{
if (radGridView1.CurrentRow != null)
{
rowIndex = radGridView1.CurrentRow.Index;
}
}
void radGridView1_SortChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
{
if (rowIndex >= 0 && rowIndex < radGridView1.ChildRows.Count)
{
radGridView1.CurrentRow = radGridView1.ChildRows[rowIndex];
object dataBoundItem = radGridView1.ChildRows[rowIndex].DataBoundItem;
int index = bindingSource1.CurrencyManager.List.IndexOf(dataBoundItem);
if (index >= 0)
{
bindingSource1.Position = index;
}
}
}
}
}