Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2275
Adding a row fails with ObservableCollection
posted

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.
Parents
No Data
Reply
  • 30945
    Offline posted

    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

Children