Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ADO.NET WPF
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()
    {
        InitializeComponent();
    }
 
    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);
        dispatcherTimer.Start();
    }
 
    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 4:40am
v2
Comments
johannesnestler at 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 at 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 at 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
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 280
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 120
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2014
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