This is a migrated thread and some comments may be shown as answers.

ObservableCollection works for adding and removing, but does not update UI on change

2 Answers 442 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Johannes
Top achievements
Rank 1
Johannes asked on 17 Mar 2014, 10:56 AM
Hi,

I'm experiencing some issues with Observablecollection<T> bound to the RadGridView.
As long as I'm inserting or deleting items in the Collection it updates just fine, but if I try to
update an item with a new value, the GridView doesn't do anything.

What I have is this:

ObservableCollection(OverviewData) ocOverviewData = new ObservableCollection(OverviewData);

which I then bind to the grid using
rgvItems.ItemSource = ocOverviewData;

When an update occurs it's just a simple iteration over the Collection like this:

foreach(OverviewData d in ocOverviewData)
{
    if(d.ReceiverName != newValue)
{
   d.ReceiverName = newValue;
}
}

The object looks like this:
public class OverviewData : INotifyPropertyChanged
{
    private string _ReceiverName;
    public string ReceiverName
    {
        get { return _ReceiverName; }
        set
        {
            if (_ReceiverName == value)
                return;                _ReceiverName = value;
            OnPropertyChanged(new PropertyChangedEventArgs("ReceiverName"));
        }
    }        private string _ReceiverAddress;
    public string ReceiverAddress
    {
        get { return _ReceiverAddress; }
        set
        {
            if (_ReceiverAddress == value)
                return;                _ReceiverAddress = value;
            OnPropertyChanged(new PropertyChangedEventArgs("ReceiverAddress"));
        }
    }        public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged(PropertyChangedEventArgs e)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, e);
    }
}

Yet, if I update any value in the observablecollection, as previously mentioned, nothing updates in the UI of the grid.
The main reason I use observablecollection is to have the grid update only the items and properties needed, not rebind
the whole grid (which can be a couple of 1000 items at a time) which would ruin the grouping, sorting and so on and incur
a break in the work process for the people using the program.

How can I make the gridview update on value changes in the items?

Thanks in advance. :)

//Johannes

2 Answers, 1 is accepted

Sort by
0
Johannes
Top achievements
Rank 1
answered on 17 Mar 2014, 01:26 PM
Additional info:

I've now tried the above code with a plain old WPF Datagrid and that DO update the information
when an item in the observablecollection gets changed. So it seems that the issue is not in the observablecollection itself
but rather the RadGridView.
0
Yoan
Telerik team
answered on 20 Mar 2014, 11:12 AM
Hello Johannes,

I've tried to reproduce the problem you report, but to no avail. I have prepared a sample project based on the code snippet you provided. You can find it attached. Please give it a try and let me know how it works at your side.

Regards,
Yoan
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
GridView
Asked by
Johannes
Top achievements
Rank 1
Answers by
Johannes
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or