Hi Rahul,
Try setting the TopRowIndex of the grid after modifying the underlying datasource of the grid. Below is a code snippet that shows this.
[c#]
int t_iTopRowIndex = this.gridDataBoundGrid1.TopRowIndex;
////////
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
int row = cc.RowIndex;
int col = cc.ColIndex;
this.gridDataBoundGrid1.FreezePainting = true;
this.gridDataBoundGrid1.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.HideAlways;
this.gridDataBoundGrid1.BeginUpdate();
this.gridDataBoundGrid1.DataSource = GetDataTable();
this.gridDataBoundGrid1.EndUpdate();
this.gridDataBoundGrid1.Refresh();
cc.MoveTo(row, col, GridSetCurrentCellOptions.ScrollInView);
////////
this.gridDataBoundGrid1.TopRowIndex =t_iTopRowIndex;
this.gridDataBoundGrid1.Focus();
this.gridDataBoundGrid1.ShowCurrentCellBorderBehavior = GridShowCurrentCellBorder.AlwaysVisible;
this.gridDataBoundGrid1.FreezePainting = false;
Please refer the modified sample for implementation and let me know if this helps.
Forum_40341_3Feb_RetainFocus.zipBest regards,
Haneef