Click here to Skip to main content
13,044,115 members (83,811 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am developing a WPF Master detail application. I would like to auto refresh my page every 5 secs. I have used a Dispatcher to achieve this. everything works fine, but the selected item is highlighted only for those 5 seconds, after 5 secs the default selected row is being displayed on the top replacing my selecteditem.

I have tried setting the issynchronizedwithcurrentitem="False", but with this set to false, the selecteditem ( for Master-detail scenario) doesn't work.

this is what I have tried,

public partial class MainWindow : Window
    WpfApplication1.PersonsEntities personsEntities;
    System.Windows.Data.CollectionViewSource personViewSource;
    System.Data.Objects.ObjectQuery<WpfApplication1.person> personQuery;
    public MainWindow()
    private ObjectQuery<person> GetpersonQuery(PersonsEntities personsEntities)
        var personQuery = personsEntities.person;
        return personQuery as ObjectQuery<person>;
    private void Window_Loaded(object sender, RoutedEventArgs e)
        DispatcherTimer dispatcherTimer = new DispatcherTimer();
        dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
        dispatcherTimer.Interval = new TimeSpan(0, 0, 5);
    protected void dispatcherTimer_Tick(object sender, EventArgs e)
        personsEntities = new WpfApplication1.PersonsEntities();
        personViewSource = ((System.Windows.Data.CollectionViewSource)  (this.FindResource("personViewSource")));
        personQuery = this.GetpersonQuery(personsEntities);
        personViewSource.Source = personQuery.Execute(System.Data.Objects.MergeOption.AppendOnly);
Posted 7-Mar-13 3:40am
johannesnestler 7-Mar-13 10:04am
so your problem is just the selection is "reset"? From a quick look I'd say you have to restore it after you reassign your personViewsSource.Source.
BuBa1947 7-Mar-13 10:08am
yes, my problem is the selecteditem-row stays idle only for those 5 secs, after 5 secs, my datagrid loads the selecteditem of the first row automatically. could you pls suggest tell me how..
johannesnestler 8-Mar-13 5:49am
Sorry I didn't see your reply - maybe next time you want to use the Reply-Button, so I get informed about your comment - please see my solution

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I think it can work like this: Get your personViewSource.View.CurrentItem before assigning the new Source. After that use personViewSource.View.MoveCurrentTo to select it again. Again: I "think" this should work, but I had no time to set up an example and try it - sorry.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100