Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2805
Recover the selected record after refresh datasource
posted

Hi,

In our application, we need to select a record , open a context menu (often launch a new window)  and have lots of data process. After close the new window, usually we'd reset the datasoucre for the xamdatagrid due to revised data.

After that the hightlighted record is missing. It's very hard for us to know which record I have processed. Is it OK just save the selected record and recover? Or  have other better way?

Thanks a lot.

  • 1230
    Suggested Answer
    Offline posted

    HI,

    We had the same issue.

    Here is the closest solution we could find and implement. Hoe it helps you too.

    Declare a local variable:

    private double gridVerticalScrollPosition = 0;

    Now just before you reload your datasource and rebind your grid:

    if (grdData.ScrollInfo != null)
         gridVerticalScrollPosition = grdData.ScrollInfo.VerticalOffset;

    Now your grid's scroll position is saved.

    After your has been re binded to your updated datasource.

    if (grdData.ScrollInfo != null)
       Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle,
           (System.Threading.ThreadStart)delegate { grdData.ScrollInfo.SetVerticalOffset      (gridVerticalScrollPosition); });

    this will scroll your grid back to the previous scroll position.

    Hope this is acceptable

  • 35319
    posted

    Hello TTran117,

     

    I am just checking if the reply was helpful for you.

     

    If you require any further assistance please do not hesitate to ask.

  • 2070
    Suggested Answer
    posted

    Hi,

     

    When you reset the data source property on the xamDataGrid to a different data source, all the previous Record instances get discarded and new ones get created. That's why simply saving the selected records and restoring them in the selected collection will not work. One way you can however do this is you can save some unique id's of the records that are selected and then after resetting the data source, find the records in the xamDataGrid with those id's and set their IsSelected property. This would effectively restore selected records.

     

    Hope this helps,

    Sandip