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

RadGridView does not respond to INotifyPropertyChanged on dynamic objects

8 Answers 368 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 14 Oct 2011, 06:09 AM

Using Telerik WPF for .NET 4

OS: Windows Server 2008

Assuming a RadGridView named "grid" is defined in XAML the following code works in

WPF Version 2011.2.712.40 but not in later versions such as 2011.2.920.40 or 2011.2.1010.40.

Calling grid.Rebind() however works for all versions.

Expected result:

Calling mi1_Click should update the value in the first cell of the grid.

public partial class MainWindow : Window
    {
        private ObservableCollection<MyDynamicObject> myObjects;
        private int Counter;
          
        public MainWindow()
        {
            InitializeComponent();
            myObjects = new ObservableCollection<MyDynamicObject>();
            for (int i = 0; i < 5; i++)
            {
                dynamic myObject = new MyDynamicObject();
                myObjects.Add(myObject);
            }
            GridViewDataColumn col = new GridViewDataColumn();
            col.Header = "Prop1";
            col.DataMemberBinding = new Binding("Prop1");
            col.DataType = typeof(string);
            grid.Columns.Add(col);
            grid.ItemsSource = myObjects;
        }
  
        private void mi1_Click(object sender, RoutedEventArgs e)
        {
            MyDynamicObject myObj = myObjects[0];
            Counter++;
            myObj.PropertyDict["Prop1"] = Counter.ToString();
            myObj.NotifyPropertyChanged("Prop1");
        }
    }
  
    public class MyDynamicObject : DynamicObject, INotifyPropertyChanged
    {
        public readonly Dictionary<string, object> PropertyDict;
        public event PropertyChangedEventHandler PropertyChanged;
  
        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
          
        public MyDynamicObject()
        {
            PropertyDict = new Dictionary<string, object>();   
        }
         
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            string propertyName = binder.Name;
            object obj1;
            result = null;
            if (PropertyDict.TryGetValue(propertyName, out obj1))
                result = obj1;
            return true;
        }
  
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            string propertyName = binder.Name;
            PropertyDict[propertyName] = value;
            return true;
        }
    }

8 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 14 Oct 2011, 08:08 AM
Hello Michael,

 The issues was fixed immediately and the fix will be part of our next internal build (Monday). I've added 2000 Telerik points to your account. 

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michael
Top achievements
Rank 1
answered on 14 Oct 2011, 08:36 AM
Hello Vlad,

thanks for your help and quick response.
Will test the new internal build on Monday.

Michael

0
Michael
Top achievements
Rank 1
answered on 18 Oct 2011, 07:18 AM
Hi Team,

while internal build 2011.2.1017.40 fixes the issue i mentioned above (thanks) the new version does not allow me to change a cell value and write a value back to my dynamic object.

To reproduce this issue just take my demo code from before and add

grid.IsReadOnly = false

in the MainWindow constructor, run the program and try to change the value of a cell. Such an attempt fails with an
"Object reference not set to an instance of an object."
error.

Compare this with 2011.2.712.40 where the code works as expected.

Michael
0
Nedyalko Nikolov
Telerik team
answered on 20 Oct 2011, 12:21 PM
Hello Michael,

We've managed to solve the problem. I'm attaching a "preview" build, which will be publicly available as internal build (Monday 24 Oct).
Could you please try your scenario and let me know how this works on your end?

Kind regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michael
Top achievements
Rank 1
answered on 21 Oct 2011, 08:17 AM
Hi Team

The good news is that with the preview build grid changes made in the UI are now propagated to my dynamic objects. So the issue I mentioned above is fixes.

However there still seems to be a problem if I paste values into the grid (from Excel for instance). (Just try to paste via CTRL-V into the grid defined in my demo code and you should see that MyDynamicObject.TrySetMember is never called. )

For me this is not critical at the moment since I am able to paste into my collection of dynamic objects by handling grid.PastingCellClipboardContent but it would be nice if this could be fixed as well.

Thanks
Michael

 

 
0
Nedyalko Nikolov
Telerik team
answered on 25 Oct 2011, 03:49 PM
Hello Michael,

I'm attaching a "preview" build which improves our support for dynamic objects. Could you please try your scenario with this build and let me know how it works?
Thank you in advance.

Regards,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Michael
Top achievements
Rank 1
answered on 26 Oct 2011, 11:46 AM
Hi Team

pasting (e.g. via Ctrl-V) still does not work, otherwise the latest attached version looks ok.

Michael

 
0
Nedyalko Nikolov
Telerik team
answered on 26 Oct 2011, 02:11 PM
Hello Michael,

Thank you for your feedback.

I forget that your dynamic object should implement GetDynamicMemberNames() in order to be able to paste in it.

public MyDynamicObject()
{
    PropertyDict = new Dictionary<string, object>();
    PropertyDict.Add("Prop1", null);
}
 
public override IEnumerable<string> GetDynamicMemberNames()
{
    return PropertyDict.Keys;
}

Best wishes,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Michael
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or