Selected row Position Changed in Grid

1 Answer 785 Views
GridView
raja
Top achievements
Rank 1
raja asked on 13 Sep 2021, 02:15 PM

Hi Team ,

 

I am new to WPF , we are using RadGridView to load data from View Model in WPF by using C# .

if selected a row and data grid refreshed or load with new items(rows) then selected row position is moving either up or down to row .

here vertical scroll bar position changed .

 

reproduce steps

1. Select any of the row from the grid.

2. Wait for the Lobby updates to happen and new tables get added to the grid

 

Expected:

  • The select state should be anchored to its grid position, updates should happen above and below the selected row (the selected row will not move)

XAML : 

<telerik:RadGridView x:Name="PokerX_CashGames_RadGridView_LobbyGrid" ItemsSource="{Binding CashGamesCollection, UpdateSourceTrigger=PropertyChanged}"
                       SelectedItem="{Binding SelectedTableItem, Mode=TwoWay,  UpdateSourceTrigger=PropertyChanged}"  Loaded="OnDataGridLoaded" Unloaded="OnDataGridUnloaded"
                       AutomationProperties.AutomationId="PokerX_CashGames_RadGridView_LobbyGrid">
        <i:Interaction.Behaviors>

xaml.cs

private void OnDataGridDataUpdated(object datagridUpdateEventArgs)
        {
            if (datagridUpdateEventArgs is DataGridUpdateEvent eventArgs && this.PokerX_CashGames_RadGridView_LobbyGrid != null)
            {
                double scrollOffset = (eventArgs.CurrentIndexOfSelectedRecord - eventArgs.PreviousIndexOfSelectedRecord) * this.PokerX_CashGames_RadGridView_LobbyGrid.RowHeight;
                GridViewScrollViewer scrollViewer = this.PokerX_CashGames_RadGridView_LobbyGrid.ChildrenOfType<GridViewScrollViewer>().First();
                if (scrollViewer != null)
                {
                    double verticalOffset = scrollViewer.VerticalOffset;
                    scrollViewer.ScrollToVerticalOffset(verticalOffset + scrollOffset);

                    
                }
            }
        }

Please help me how can i fix this .

raja
Top achievements
Rank 1
commented on 14 Sep 2021, 03:19 PM

Hi Team 

 

any update on this , please  this is an priory issue to our aplication

 

pls help as soon as possible

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 15 Sep 2021, 08:23 AM

Hello Raja,

The described functionality is not supported by RadGridView. You can use the ScrollToVerticalOffset() method of the GridViewScrollViewer to manually adjust the scroll position, but this code should be planted carefully since its proper working depends on the measure and arrange of the data grid and its rows.

A more reliable approach that I can suggest you is to use the pinned rows feature of the RadGridView control. You can pin the selected item so it always positions on top or bottom of the rows list when you scroll up or down.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

raja
Top achievements
Rank 1
commented on 15 Sep 2021, 09:35 AM

Hi Martin Ivanov,

 

thank you for quick update on my query .

 

can you please help with a sample code on ScrollToVerticalOffset() .

we are using  version 2021.2.615.45. 

 

please help to with a complete solution .

Regards

Raja

 

Martin Ivanov
Telerik team
commented on 22 Sep 2021, 01:30 PM

I've attached a small example showing one way to cache and update the VerticalOffset. I hope it helps.
Steve
Top achievements
Rank 1
commented on 29 Jun 2022, 07:56 AM

We would also like this functionality - its very important to our application.  As Raja requests, the expected behaviour we need is that the selected row does not change position as new rows are added anywhere above or below, especially when the grid is sorted by one any one of the columns chosen by our users.

Please can you provide a fix for this?

The solution you provide utilising ScrollToVerticalOffset doesn't work if you sort the column.  We would like a fix that works for all scenarios.

Thanks in advance.

Steve

Martin Ivanov
Telerik team
commented on 30 Jun 2022, 08:56 AM

There is already a feature request logged in the feedback portal to add a mechanism to fix the scrolling to current viewport. You can find it in our feedback portal where you can track its status: https://feedback.telerik.com/wpf/1354943-gridview-do-not-scroll-control-when-new-items-are-added-to-the-top

In the meantime, you can use the approach from my previous project. I've updated the code (see the attachment of this reply) to take into account also the sort order in the data control. I hope that helps.

 

Steve
Top achievements
Rank 1
commented on 01 Jul 2022, 08:44 AM

Thanks Martin, I've commented on the link you sent - any eta on this ?   The workaround you send doesn't work if the grid is sorted by one of the columns unfortunately so its not of use to us right now.  I'd really like the fix, many thanks

 

Martin Ivanov
Telerik team
commented on 01 Jul 2022, 09:07 AM

I've replied to your post in the feedback portal. Currently, we cannot bind to a timeframe for implementing this. However, we have updated its priority according to your feedback. This doesn't mean that the feature will enter the next planning phase, but it slightly pushes it in the features queue.

As for the workaround, can you tell me in what conditions exactly it doesn't work? I am asking this because I've tested it with sorted column also, but the code worked properly on my end.

Tags
GridView
Asked by
raja
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or