This is a migrated thread and some comments may be shown as answers.

Scrolling to previous selection

1 Answer 89 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Sean asked on 30 Jun 2009, 07:04 AM
Hi, I have a RadGridView that is bound to a DataTable.
I refresh the data binding every 30 seconds.
Currently before I refresh I store the currently selected rows and reselect them on rebinding to make the user experience as seamless as possible.
This works fine until I have enough items to cause it to scroll. When I have items selected at the bottom of the list, on refresh the selection disappears even though I have it added to the selectedrows collection, and the scrollbar is at the top with the item out of view. When I manually scroll down, I see that my previous selection has disappeared.
Also I tried using the code below as suggested in the forum to scroll to my selected row.
int visualRowsCount = this.radGridView1.GridElement.VisualRows.Count;   
this.radGridView1.GridElement.ScrollToRow(indexToScroll - visualRowsCount + 3);  
But my visualrows.count is always returned as zero. And when I call the ScrollToRow method, it always gives an outofbounds exception.
I am using the binding below where docs is a DataTable.
this.gridDocs.MasterGridViewTemplate.DataSource = docs
Am I doing something wrong here?

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 03 Jul 2009, 09:15 AM
Hi Sean,

This is because the rows contained in the SelectedRows collection are valid only before changing the data source. You should save the row indexes instead. Please take a look at the code snippet below:

List<int> selectedRowsIndexes = new List<int>(); 
foreach (GridViewDataRowInfo row in this.radGridView1.SelectedRows) 
this.radGridView1.DataSource = GetDataSource(); 
foreach (int index in selectedRowsIndexes) 
    this.radGridView1.Rows[index].IsSelected = true

I hope this helps. Should you have any other questions, I will be glad to help.

All the best,
the Telerik team

Instantly find answers to your questions on the newTelerik Support Portal.
Check out the tipsfor optimizing your support resource searches.
Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question