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

[Solved] Bring current item into view problem

3 Answers 92 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Patrick
Top achievements
Rank 1
Patrick asked on 20 Mar 2014, 09:44 AM

Hello,

I have a problem with the positioning of the current element in the visible part of the grid when reloading a page.

Grid definition :
<Grid:RadDataGrid ItemsSource="{Binding Diffuseurs}"  SelectedItem="{Binding SelectedDiffuseur,Mode=TwoWay}"                   IsSynchronizedWithCurrentItem="True">

I displayed the first time a page associated with a persistent DataContext and I select an item in the grid :
-> Everything is correct ( selectedItem , currentItem ) and the binding property in the ViewModel.

I display another page then come back to my previous page by Frame.Navigate method(typeof(MyPage)) :
-> The page is reloaded and the SelectedItem property of the grid is updated from my DataContext but against the property CurrentItem remains null and my current item is not returned in the visible part of the grid.

When I try to use the ScrollItemIntoView method in an event of the grid (Loaded, DataBindingComplete, SelectionChanged ) it doesn't work, CurrentItem remains null.

Thank you in advance for your help.

Regards

Patrick

3 Answers, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 24 Mar 2014, 01:21 PM
Hi,

You can move the current item of the RadDatGrid to its previous position through the IDataView.MoveCurrentTo(..) method. The IDataView interface provides a view over the already computed data within the RadDataGrid. You can get it through the RadDataGrid.GetDataView() method. So in this case the code should look like this:

this.grid.GetDataView().MoveCurrentTo(previousCurrentItem);

Note that the RadDataGrid will automatically bring this item into view so the RadDataGrid.ScrollItemIntoView() method is not needed.

Let me know if this works for you.


Regards,
Ivaylo Gergov
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
Patrick
Top achievements
Rank 1
answered on 24 Mar 2014, 04:53 PM

Hi Ivaylo,

I used this method but how and where do I use it. In the event of the grid (DataBindingComplete, SelectionChange) or page (Loaded), the method always returns false.

In which context MoveCurrentTo returns false ?

Regards
Patrick

0
Ivaylo Gergov
Telerik team
answered on 25 Mar 2014, 04:03 PM
Hi,

The MoveCurrentTo(..) method returns false when for some reason the RadDataGrid still makes some internal computations over its data and the data is not ready yet. Basically, the RadDataGrid.DataBindingComplete event/command assures that all the internal processes that operate with its data are done, but this means that this event will fire in many cases like after filtering,grouping and etc. In this case I think it would be a good idea if you execute this method in the RadDataGrid.Loaded event. I have tried this approach in a plain project and it seems that everything works as expected. Could you please give it a try and tell us if this works for you? If not, it will be helpful if you send us a project where this does not work and we will further investigate for a reasonable solution.

I am looking forward to your reply.

Regards,
Ivaylo Gergov
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
Tags
Grid for XAML
Asked by
Patrick
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Patrick
Top achievements
Rank 1
Share this question
or