Home Forums WinForms controls Xceed Grid for WinForms Focusing on previously selected cell (after refreshing Grid) Reply To: Focusing on previously selected cell (after refreshing Grid)

User (Old forums)
Member
Post count: 23064

Or like this:

int selectedGridRowIndex = -1;
string selectedGridCellFieldName = “”;

if (this.gridControl1.CurrentRow != null && this.gridControl1.CurrentCell != null)
{
this.selectedGridRowIndex = ((Xceed.Grid.DataRow)this.gridControl1.CurrentRow).Index;
Xceed.Grid.DataCell cell = (Xceed.Grid.DataCell)gridControl1.CurrentCell;
this.selectedGridCellFieldName = cell.FieldName;
}

gridControl.refresh();

if (this.selectedGridRowIndex != -1)
{
if(this.gridControl1.DataRows.Count >= this.selectedGridRowIndex)
{
if(this.gridControl1.DataRows[this.selectedGridRowIndex-1].Cells[this.selectedGridCellFieldName] != null)
{
if (((Xceed.Grid.DataCell)this.gridControl1.DataRows[this.selectedGridRowIndex-1].Cells[this.selectedGridCellFieldName]).Visible)
{
this.gridControl1.CurrentCell = this.gridControl1.DataRows[this.selectedGridRowIndex-1].Cells[this.selectedGridCellFieldName];
this.gridControl1.CurrentCell.BringIntoView();
}
}
}
}

Imported from legacy forums. Posted by C# (had 3655 views)