We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridDataControl displaying duplicated data

Thread ID:

Created:

Updated:

Platform:

Replies:

104091 Jun 20,2012 09:56 PM UTC Jun 25,2012 04:14 AM UTC WPF 2
loading
Tags: GridControl
Joshua Cauble
Asked On June 20, 2012 09:56 PM UTC

I am in the process of creating a screen where I am using the reactive framework to handle async operations for my WPF application.  On my screen I have a dropdown box that has a list of say People.  When I change the dropdown box it will trigger my command, go to the database and load the information for that user.  

Now when the screen first comes up everything is peachy.  The default record has its data and it renders correctly.  However if we change the dropdown and select a different user, then after it's done switch back the data comes back duplicated.  

So the general process is this:

On change of the combo, clear the datasource for the grid, then load the datasource with the data for the next selected item.  When this occurs as we navigate the combo it is creating, for lack of a better term, shadow records.  So if my collection has 3 items it I can get anywhere from 3-6 items that show up.  

Here is my Control definition:

<syncfusion:GridDataControl Grid.Column="0" ShowAddNewRow="False" ItemsSource="{Binding UserData}" AllowDelete="False" AllowEdit="False" AllowGroup="False" AutoPopulateColumns="False" AutoPopulateRelations="False" ExcelLikeCurrentCell="False">
                        <syncfusion:GridDataControl.VisibleColumns>
                            <syncfusion:GridDataVisibleColumn HeaderText="Preference Name"  Binding="{Binding UserPreferenceName}" Width="200" IsReadOnly="True" AllowResize="True"/>
                            <syncfusion:GridDataVisibleColumn HeaderText="Last Updated" IsReadOnly="True" Binding="{Binding UpdateTS, StringFormat=d}" Width="100" MinimumWidth="100"/>
                        </syncfusion:GridDataControl.VisibleColumns>
                    </syncfusion:GridDataControl>

Here is my View Model (roughly):


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReactiveUI;
using ReactiveUI.Xaml;
using MyCode.Models.SupportObjects;
using MyCode.Core;
using MyCode.Core.Extensions;
using MyCode.Models.Main;
using System.Reactive.Linq;

namespace MyCode.ViewModels
{
    public class UserPreferenceManagerVM : ReactiveValidatedObject
    {
        public UserPreferenceManagerVM(string defaultUser)
        {
            SelectedUser = defaultUser;
            FetchPreferencesForUser = new ReactiveAsyncCommand();
            FetchPreferencesForUser.RegisterAsyncAction(_ => LoadUserPreferenceData());
            UserData = new ReactiveCollection<UserPreference>();

            FetchPreferencesForUser.Execute(null);

            this.ObservableForProperty(x => x.SelectedUser).Subscribe(_ => FetchPreferencesForUser.Execute(null));

            LoadUserProfiles();
        }
        
        private string _SelectedUser = string.Empty;
        public string SelectedUser
        {
            get { return this._SelectedUser; }
            set { this.RaiseAndSetIfChanged(x => x.SelectedUser, value); }
        }

        public ReactiveCollection<UserPreference> UserData
        {
            get;
            protected set;
        }

        public ReactiveCollection<UserProfile> UserProfiles
        {
            get;
            protected set;
        }


        public ReactiveAsyncCommand FetchPreferencesForUser
        {
            get;
            protected set;
        }

        private void LoadUserPreferenceData()
        {
                UserData.Clear();
                if (SelectedUser == SystemVariables.ActingUser)
                {
                    if (MyCode.Core.Cache.Items.ContainsKey(CacheKeys.UserPreferences))
                    {
                        Dictionary<string, UserPreference> prefs = MyCode.Core.Cache.GetItem<Dictionary<string, UserPreference>>(CacheKeys.UserPreferences);
                        if (prefs != null)
                        {
                            foreach (var item in prefs)
                            {
                                UserData.Add(item.Value);
                            }
                        }
                    }
                }

        }

        private void LoadUserProfiles()
        {
            if (MyCode.Core.Cache.Items.ContainsKey(CacheKeys.UserProfiles))
            {
                List<UserProfile> profiles = MyCode.Core.Cache.GetItem<List<UserProfile>>(CacheKeys.UserProfiles);
                if (profiles != null)
                {
                    UserProfiles = new ReactiveCollection<UserProfile>(profiles.OrderBy(x=>x.LastName));
                }
            }
        }
    }
}

The Objects are basic objects that implement the INotifyPropertyChanged stuff.


Any ideas why I would be getting the duplicate data?

Attached is the screenshot of a dummy app that replicates the problem.  Good state, onload of the app, and Bad State after I have changed the combo and then gone back to another user.


Screens_3b2deb40.zip

Joshua Cauble
Replied On June 21, 2012 03:04 PM UTC

Nevermind I found the issue.  It had to do with updating the collection on a background thread and needing to call a reset process.  Using the Reactive UI they had a method process to handle this type of scenario and everything is now working as designed.

Rajasekar [Syncfusion]
Replied On June 25, 2012 04:14 AM UTC

Hi Joshua,

 

Thanks for updating us the status and we are glad to hear that the reported problem has been resolved at your end.

 

Thanks,

Rajasekar


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;