解决dev GridControl 刷新数据后,滚动条恢复原来位置
找了半天scroll,结果却是TopRowIndex的事。
1、触发GridView_TopRowChanged()事件
2、设置TopRowIndex
int topIndex = -1; private void gridView2_TopRowChanged(object sender, EventArgs e) { topIndex = gridView2.TopRowIndex; } private void refreshView2() { string sql = "select * from [A数据分析表]"; DataTable dt= db.GetTable(sql); gridControl2.DataSource = dt; gridView2.TopRowIndex = topIndex;//就是这句 } private void button1_Click(object sender, EventArgs e) { refreshView2(); }
怀仁怀朴,唯真唯实。