I am using MVVM. My VM has two properties (1) [Data] which returns ObservableCollection<Account> and (2) [AccountAttributes] which returns ObservableCollection<AccountAttribute>.
I View's code behind DataContext set to above class. [Data] is bound to xamDataGrid and it works fine. I want to bind an property in [AccountAttributes] to XamComboEditor which is linked to a column in xamDataGrid. What is the exact syntax in XAML? If I change [AccountAttributes] to List<string> it works fine but want it to be an ObservableCollection.
Thanks.
Hello Jay,
Thank you for the sample application you have provided.
I tested the behavior you have described inside the window's constructor and when the following lines are executed (they were uncommented by default), I was able to successfully add new records by using the AddNew record functionality at runtime.
/* * * UN-COMMENT THE NEXT TWO LINES AND YOU CAN NOT ADD NEW ROW IN THE GRID * */companies.Data.Add(new Company("Microsoft", "111"));companies.Data.Add(new Company("Intel", "222"));
You mentioned that a property of your DataItem is null when adding it to the XamDataGrid (presuming through the AddNew record). Whenever we type inside a cell of the AddNew record, the XamDataGrid automatically detects that and creates a new record and a new DataItem instance for it by using its parameterless constructor (the RecordAdded event is fired). Since the cell is still in edit mode at this time and the record has not been committed to the XamDataGrid yet, it is expected for the property that corresponds to this cell's value to return null. As soon as we leave the cell (for example enter into the next cell of the same record) or we commit the record, the setter of the property will trigger and the value will be set.The sample application you have provided does not use the XamComboEditor control and this is why I cannot refer to its behavior when using the data from this sample.
If you have any questions, please let me know.
Please see attached app. See main window's code-behind
Since the behavior in regards to the selection and the binding is strongly dependent on the implementation of the application, it would be best if you could provide me with a sample, where the issue is isolated and reproduced.
Would you also please provide me with detailed steps for reproducing the issue, along with the expected and the actual results from the interaction?
Okay, in my application, it picks up the correct Item.AccountAttribute for existing rows (i.e. binding seems to work). However, when I add a new row, it passes a null for DataItem.AccountAttribute. It does not save the selected AccountAttribute to Items.AccountAttribute in VM.
Also, this may be related: I have child xamDataGrid bound to an ObervableCollection and the Get{} accessor has following:
return new ObservableCollection<Account>(_data.Where(p => p.AccountId == _accountId));
when _accountId = 0, the above would return an empty collection. When this happens, I am not able to add new row.
I tested the behavior you have described (with 16.2) in regards to the SelectedDataItem property always being null and I was not able to reproduce it. Only if no record is currently selected, the SelectedDataItem will be null.
If you have integrated the code from the sample within your application, would you please make sure you have also set the SelectedDataItemsScope property of the XamDataGrid to RecordsOrCells.