Click here to Skip to main content
15,944,401 members
Please Sign up or sign in to vote.
4.00/5 (1 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);
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

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.
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900