I have a very simple data source, a System.Collection that contains 'person' records. The person class has 2 properties, one is a string and the the other is a bool field.
This binds as expected in the XamGrid and I get a XamCheckBox for my boolean field. However, when I change the value of the check box I get the following exception in the output window "System.Windows.Data Error: 8 : Cannot save value from target back to source. BindingExpression:Path=IsChecked; DataItem='XamCheckEditor' (Name=''); target element is 'ValueEditorCheckBox' (Name='PART_FocusSite'); target property is 'IsChecked' (type 'Nullable`1') ArgumentException:'System.ArgumentException: oldValue has incorrect type for this property"
If I change my values programatically the check boxes in the grid reflect the changes so I know I am bound to the correct fields.I get this same behavior whether I use automatically generated fields or manually generated fields.
Did I miss something in my class maybe?
Thanks!!
Hello,
I tried to reproduced the scenario but I could not get the error. Please attach a sample project ( illustrating the problem ) to take a closer look.
Alex.
Here is a sample. Also, I get a stack overflow when I try to set the name field through the grid.
The problem obviously is in the encapsulation of the property (IsSelected).
There is a lazy way in the Visual Studio for encapsulation of fields. You select the field, right click it Reflactor - Encapsulate Field and the studio will automatically create the Property for you.
Another suggestion is to use BindingList<Person> instead of a class that inherits ArrayList. This is because the BindingList is much more flexible with the XamDataGrid. For example if you add a parameterless constructor to the Person class (and maybe in it set some default values for the new Person object) and set AllowAddNew to True you will be able to add new recors in the collection in the application, while with ArrayList that is not possible.
Here are the changes I made:
using System.ComponentModel;
BindingList<Person> p = new BindingList<Person>(); p.Add(new Person(true, "John")); p.Add(new Person(false, "Jane")); xamDataGrid1.DataSource = p;
public bool IsSelected { get { return _isSelected; } set { _isSelected = value; } }
public string Name { get { return _Name; } set { _Name = value; } } public Person() { }
and in the xaml:
<igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AllowAddNew="True" AddNewRecordLocation="OnTopFixed" AutoGenerateFields="True"/> </igDP:XamDataGrid.FieldLayoutSettings>
Hope this helps,
The site has been updated and some of the data has been lost during the conversion. Please attach the sample once again. Sorry for the inconvenience.
Thank you for your responses. I have followed your instructions and I still have the same problem (project is attached). I even tried making a people class that inherits from BindingList<Person> but it also did not work.
The complete exception is attached as a text file in the project zip file.
This project does work on Vista-64 computers just not on 32 bit. I have also opened a case with Infragistics
This is because the Record does not exit EditMode - if you uncheck/check and then press Enter to exit EditMode the setter will fire as expected. It works correctly. My suggestion still is to use BindingList, set the data source of the grid after you populate the collection with data and avoid the class People inheriting an ObservableCollection.
I have the same problem using a binding list. Strangely enough if I move the project to a 64-bit machine I don't have any issues at all.
It seems that the property setter is one event behind. I mean, if I have 2 items in the list and I unclick the first check box the property setter never fires. If I then uncheck the second check box the setter is fired but for the first item's data.
Attached is another sample.