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

ObservableCollection<X> - If I change X.property, RadGridView does not update

7 Answers 299 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 05 Jun 2009, 05:01 PM
Hi All,

I have a RadGridView, whose ItemsSource is an ObservableCollection<X>.  Using the example in the demo about attaching a RadContextMenu to each row in the GridView_RowLoaded event handler, I add a context menu.  In the OnMenuItemClick, I can get the GridViewRow, and the ObservableCollection<X>, etc.

If the action is delete, then collection.remove((X)row.DataContext) removes the row and the grid reflects this.  I have a few other actions on the context menu which change other properties of X, say X.Active = true/false.  The corresponding columns in the grid (rendered as a checkbox for X.Active is bool) do not update.  However, the collection is definitely changed as the context menu knows what options to enable/disable based on this property (as enabled/disabled in the OnMenuOpened()) handler.

I want to tell the gridview that this row has been changed.  I don't want to remove and re-add the row, which does work.

I have spent a while searching for a solution to this with no luck.  I admit I am sitll quite new to Silverlight, but not to UIs and there must be a way to have a notification occur when a property changes.

Please advise and Thanks,
Tim

7 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Top achievements
Rank 1
answered on 07 Jun 2009, 05:29 PM
Hi Tim,

Changing properties of an object inside ObservableCollection<T> will not raise CollectionChanged - RadGridView will be refreshed automatically only when on CollectionChanged!

Possible implementation will be to raise explicitly CollectionChanged event on PropertyChanged if these objects are INotifyPropertyChange

Vlad
0
Tim
Top achievements
Rank 1
answered on 08 Jun 2009, 02:55 PM
Hmm.  After a bit of further investigation, it appears that if, in my ObservableCollection<X>, X : INotifyPropertyChanged, and I properly raise the change event, then the grid does update.

Thanks for the clue,
Tim

0
Krlos
Top achievements
Rank 1
answered on 30 Jul 2009, 04:44 PM
Example :

public class X : System.ComponentModel.INotifyPropertyChanged
{

    private string _field;
    public string Field
    {
        get { return _field; }
        set
        {
            if (_field != value)
            {
            _field = value;
            OnPropertyChanged("Field");
            }
        }
    }
    public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged(string propertyName)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
     }
}

0
george
Top achievements
Rank 1
answered on 27 Oct 2010, 11:04 PM
hi

i am using radgridview in usercontrol and its not binding at all please advice

<UserControl xmlns:Views="clr-namespace:ClientModule.Views" >
<Views:InfoGridView />
</UserControl>


<UserControl x:Class="ClientModule.Views.InfoGridView">
<Controls:RadGridView x:Name="radGridViewOverview" IsReadOnly="True" AutoGenerateColumns="False" ItemsSource="{Binding RepaymentInfo, Mode=TwoWay, Path=RepaymentInfo, ElementName=PosSearchView}" >
</UserControl>

0
Vlad
Telerik team
answered on 28 Oct 2010, 07:23 AM
Hi george,

 Can you verify what will happen if you change the grid temporary to a simple ListBox with the same binding?

Kind regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vivek
Top achievements
Rank 1
answered on 18 Jul 2017, 07:52 PM

Hello Tim, I have a viewmodel with an ObservableCollection<X> where X does implement INotifyPropertyChanged and so does my ViewModel and yet when I bind it to a RadGridView I do not get updates when any property within X changes neither if I add/delete rows in the UI on the collection itself.

I am a bit flummoxed, so would appreciate if you can help me resolve this issue.

0
Dinko
Telerik team
answered on 21 Jul 2017, 01:16 PM
Hi Vivek,

I have tested the approach explained in the last post using the latest version of our controls and wasn't able to reproduce it on my side. I attached to this reply the project which I used to test this scenario. Can you give it a try and let me know if I missing something. You can modify the project to reproduce this behavior and set it back.

Regards,
Dinko
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Tim
Top achievements
Rank 1
Answers by
Vlad
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Krlos
Top achievements
Rank 1
george
Top achievements
Rank 1
Vlad
Telerik team
Vivek
Top achievements
Rank 1
Dinko
Telerik team
Share this question
or