Home Forums WinForms controls Xceed Grid for WinForms Forced Row Change in Databound grid Reply To: Forced Row Change in Databound grid

User (Old forums)
Member
Post count: 23064

What you could do (and what I do): store the current row index in a variable before calling BeginInit, and set the current row back after calling EndInit.
Here’s some code I use:<code>int rowIndex = -1, columnIndex = -1;
private void SaveCursorPosition() {
if (grid.DataRows.Count == 0)
rowIndex = -1;
else {
Xceed.Grid.DataRow row = grid.CurrentRow as Xceed.Grid.DataRow;
if (row != null) rowIndex = grid.GetSortedDataRows(true).IndexOf(row);
else rowIndex = -1;
}
if (grid.CurrentColumn != null)
columnIndex = grid.Columns.IndexOf(grid.CurrentColumn);
else columnIndex = -1;
}
private void LoadCursorPosition() {
if (rowIndex >= 0 && rowIndex < grid.GetSortedDataRows(true).Count) {
Xceed.Grid.DataRow row = grid.GetSortedDataRows(true)[rowIndex];
if (row.CanBeCurrent && row.Visible) {
row.BringIntoView();
grid.CurrentRow = row;
if (row.CanBeSelected) {
grid.SelectedRows.Clear();
grid.SelectedRows.Add(row);
}
}
}
if (columnIndex >= 0 && columnIndex < grid.Columns.Count)
grid.CurrentColumn = grid.Columns[columnIndex];
}</code>

Imported from legacy forums. Posted by Tommy (had 374 views)