Hi,
RadGridView behavior after update/insert row is different
between NewRowPosition="Top" and NewRowPosition="Bottom".
When position is defined "top", after saving the scroll is on
the same position as before saving. However, when the position is defined "Bottom", after saving
it scrolls to top.
Workaround with ScrollIntoView() is not useful in my case, because I may have
many rows updated.
How can I achieve the same behaviour as NewRowPosition="Top" after saving?
Thanks
7 Answers, 1 is accepted
I tried to reproduce the behavior you've described, but was, unfortunately, unable to do so. In both cases, when I add or edit a row, the scroll offset does not change.
Could you please have a look at the attached project and let me know whether I'm missing something important? If that is the case, please provide more details on the exact steps needed to reproduce this behavior.
Thank you in advance for your cooperation on the matter.
Regards,
Dilyan Traykov
Telerik by Progress
Hi, I've been able to reproduce the problem, please find project attached.
Change the following:
1. In MyViewModel add:
public QueryableCollectionView GridRows { get; set; } //Instead of Clubs
2. Add constructor in MyViewModel
public MyViewModel()
{
GridRows = new QueryableCollectionView(Clubs);
}
3. Add function in MyViewModel
public void AddClubs()
{
//Add Or Update
GridRows.Refresh();
}
5. In MainWindow.xaml in clubsGrid change to:
ItemsSource="{Binding GridRows}"
6. In MainWindow code behind:
private void Button1_Click(object sender, RoutedEventArgs e)
{
var parent = clubsGrid.DataContext as MyViewModel;
if(parent == null ) return;
parent.AddClubs();
}
Scenario :
1) Update any row in grid (in the
middle of a grid).
2) Click "Save". The
scroll moves to top.
When NewRowPosition="Top" it does not happen.
Is there any reason you're calling the QueryableCollectionView's Refresh method? From what I observe, simply modifying/adding objects to the bound ObservableCollection will result in the desired result - no scrolling is done, but RadGridView is still notified about the changes made.
public
void
AddClubs()
{
this
.Clubs[0].Name =
"asdf"
;
this
.Clubs.Insert(0,
new
Club() { Name =
"Tottenham"
});;
}
Regards,
Dilyan Traykov
Telerik by Progress
Hi,
The reason we use the Refresh function is because of another issue that happens when a combobox is integrated within the grid.
As said earlier this works perfectly well when NewRowPosition="Top" and not NewRowPosition="Bottom".
We need this to work in the same way.
Thanks.
This undesired behavior can be avoided by adding the following lines before and after the AddClubs method:
var scrollViewer =
this
.clubsGrid.FindChildByType<GridViewScrollViewer>();
var startOffset = scrollViewer.VerticalOffset;
parent.AddClubs();
scrollViewer.ScrollToVerticalOffset(startOffset);
Please let me know if this would work for you.
Regards,
Dilyan Traykov
Telerik by Progress
Thanks very much!! this worked.
However, I still think this should be resolved instead of such a workaround :-)