Whenever a sort filter is applied to my radgridview, it holds the selectedItem and scrolls to it further down in the list. How to I programatically scroll to the top or disable this from jumping to the selected item? (Sorting is pre-set in the UI component, not programmatic)
I've been using Telerik for years now and have a boatload of "Helper" methods i use for all variety of issues. One of these might help you - I write in VB.net but it shouldn't take more than a moment to convert to C# if that's your bag:
Public Sub SelectRow(ByVal pGrid As RadGridView, ByVal pRow As GridViewRowInfo) If IsNothing(pGrid) Then Exit Sub If IsNothing(pRow) Then Exit Sub
pGrid.CurrentRow = pRow pRow.IsSelected = True pRow.IsCurrent = True pRow.EnsureVisible() End Sub
Public Sub SelectFirstRow(ByVal pGrid As RadGridView) If IsNothing(pGrid) Then Exit Sub
If pGrid.Rows.Count > 0 Then pGrid.CurrentRow = pGrid.Rows(0) pGrid.Rows(0).IsSelected = True pGrid.Rows(0).IsCurrent = True pGrid.Rows(0).EnsureVisible() End If End Sub
The first method you pass in the Grid and the Row and it'll select, highlight and make sure it's visible.
The second method does that same except it'll be the first row. For *MY* application there was no need to test to see if the first row was visible or not so if that's possible for your ap, you'll want another method to crawl the row collection to find the first visible row and use that index instead of 0 like I do above.
When you apply the sorting filter in the radGridView the scrollbar doesn't change its position by default. To programmatically scroll to the top row you can try the SortChanged event in the radGridView and use the ScrollToRow function.
Hello Sean!
I've been using Telerik for years now and have a boatload of "Helper" methods i use for all variety of issues. One of these might help you - I write in VB.net but it shouldn't take more than a moment to convert to C# if that's your bag:
Public Sub SelectRow(ByVal pGrid As RadGridView, ByVal pRow As GridViewRowInfo)
If IsNothing(pGrid) Then Exit Sub
If IsNothing(pRow) Then Exit Sub
pGrid.CurrentRow = pRow
pRow.IsSelected = True
pRow.IsCurrent = True
pRow.EnsureVisible()
End Sub
Public Sub SelectFirstRow(ByVal pGrid As RadGridView)
If IsNothing(pGrid) Then Exit Sub
If pGrid.Rows.Count > 0 Then
pGrid.CurrentRow = pGrid.Rows(0)
pGrid.Rows(0).IsSelected = True
pGrid.Rows(0).IsCurrent = True
pGrid.Rows(0).EnsureVisible()
End If
End Sub
The first method you pass in the Grid and the Row and it'll select, highlight and make sure it's visible.
The second method does that same except it'll be the first row. For *MY* application there was no need to test to see if the first row was visible or not so if that's possible for your ap, you'll want another method to crawl the row collection to find the first visible row and use that index instead of 0 like I do above.
Hope this helps!
Cheers.