Hi, I'm trying to add a row to a XamDataGrid programmatically and I keep getting an exception with the error "Can't add items to a DataPresenter that is bound to a datasource." My FieldLayoutSettings has AllowAddNew=True. My call is
dgPatients.DataItems.Add( e.Patient );
where dgPatients is the XamDataGrid, and e.Patient is a patient object. The DataSource of the grid
was populated with an ObservableList.
Thank you.
Hello Mike,
I have been looking into the behavior that you have described and when you click on a record it becomes Active and Selected. After adding the new Patient to the DataSource of the XamDataGrid and set the ActiveDataItem to the newly added item, the Record that correspond to that Patient becomes active. The record that was previously active is no longer active, but it stays selected. In that case, the previous active record is selected and the newly activated record is active and both records appear highlighted. You can force the selected record to not appear highlighted by clearing the selected record before setting the ActiveDataItem property of the XamDataGrid. Here is an example for that:
(dgPatients.DataSource as ObservableCollection<Patients>).Add(e.Patient);
dgPatients.SelectedItem.Records.Clear();
dgPatients.ActiveDataItem = e.Patient;
If you have any further questions please do not hesitate to ask.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Krasimir,
Perfect, thank you, it was just what I needed.
Did you guys ever disuss the larger issue of why GetRecordFromDataItem would always return null except after adding a record? I had to write my own find method. Any thoughts at all?
Thanks again Krasimir for coming through for me yet again.