[Solved] Reposition row after reloading grid

1 Answer 5 Views
GridView
Carl
Top achievements
Rank 1
Bronze
Iron
Iron
Carl asked on 07 Sep 2026, 07:53 PM

I'm working with a Winforms grid that may, or may not, have paging set. I need to open a popup editor and edit a record. After I save, I need to pull the data from the database again (other people may have made changes on other workstations) and want the grid to return to the position it was at when the use edit the record.

Given the layout below where only Rows C, D, and E are visible, if the user edits Row D and then saves, I want the grid to look exactly like this with D as the current row.

Row A
Row B
----------
Row C
Row D (edited row)
Row E
----------
Row F

Here is what I tried but its not working as I expected.

int currentRow = gvMemos.CurrentCell.RowIndex;
int scrollPos = gvMemos.TableElement.VScrollBar.Value;

//Do something

if (scrollPos > 0)
    gvMemos.TableElement.VScrollBar.Value = scrollPos;

if (currentRow > 0)
{
    gvMemos.TableElement.ScrollToRow(currentRow);
    gvMemos.CurrentRow = gvMemos.Rows[currentRow];
    //gvMemos.CurrentRow.EnsureVisible();
}

Thanks

Carl

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 08 Sep 2026, 12:20 PM

Hello, Carl,

I am not familiar in details with your custom project setup, but following the description here, the core issue seems that you're capturing/restoring by row index and raw scrollbar value, but after you re-fetch data from the database.

The rebound row collection is a completely new set of GridViewRowInfo objects — the old index may now point to a different record (according to how rows get shifted after reloading the grid).

Also, if paging is enabled, RowIndex only reflects rows on the current page. Note, when paging is enabled, ChildRows includes only the rows on the current page. If you need the row number in the full visible order, use (RadGridView.MasterTemplate.DataView as GridDataView).Indexer.Items. So an index captured before rebind is meaningless after rebind if paging shifts the page. More information is available here: Use GridDataView.Indexer for Paged Data

Setting VScrollBar.Value manually before the grid has recalculated its scroll range (which happens after data is rebound and rows exist) is unreliable — the scroll range gets reset/recomputed when the data source changes, so your manually-set value gets overridden or clamped.

What I can suggest in this case is to track the record by its unique key (primary key, data bound item Id, etc.), not by index/scrollbar position. After rebinding, look up the row for that key and use EnsureVisible()/CurrentRow to reposition — and if paging is on, also set the correct PageIndex. Avoid relying on scrollbar value and use row indexes instead.

For example: 

// Before edit / before refresh: remember the primary key of the row being edited
object editedKey = ((YourRecordType)gvMemos.CurrentRow.DataBoundItem).Id;

// ... open popup editor, save, then re-fetch data from DB and rebind gvMemos.DataSource ...

// After rebind: find the row again by key
var rowToSelect = radGridView1.Rows.FirstOrDefault(r => ((YourRecordType)r.DataBoundItem).Id == editedKey);

if (rowToSelect != null)
{
    gvMemos.CurrentRow = rowToSelect; //setting CurrentRow property will automatically scroll to the exact row
    rowToSelect.IsSelected = true;
    rowToSelect.EnsureVisible();       // consider using EnsureVisible() that scrolls it into view, respecting current scroll layout to ensure the current row is visible
}

Feel free to adopt this suggest in your custom implementation as it shows the main idea, however the exact implementation should be according your custom specific logic.

I hope this information helps. If you have other questions, let me know.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Modernizing a WinForms application? Use the AI-powered WinForms Converter to simplify migration to Telerik UI for WinForms.
Tags
GridView
Asked by
Carl
Top achievements
Rank 1
Bronze
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or