Home Forums WPF controls Xceed DataGrid for WPF Getting Error When Editing Newly Added Row.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22044 |

    Hello,

    I have created a datagrid and binded data with it.

    <xcdg:DataGridControl Template=”{StaticResource datagrid_template}” x:Name=”TaskListGrid2″
    ItemsSource=”{Binding Source={StaticResource MyFriends}}”
    ItemContainerStyle=”{StaticResource datarow_style}”
    PagingBehavior=”TopToBottom”
    EditTriggers=”None”
    CellEditorDisplayConditions=”CellIsCurrent”
    CellErrorStyle=”{StaticResource cell_error}”
    AddingNewDataItem=”AddingDataItem”>

    Here MyFriends is ObjectDataProvider.
    <ObjectDataProvider x:Key=”MyFriends” ObjectType=”{x:Type local:People}” />

    ObservableCollection is inherited in People Class.
    public class People : ObservableCollection<Person>

    Person is the class having all the properties which are the columns of my datagrid. In this class INotifyPropertyChanged is also implemented.

    For Inserting data I have written the following code inside View of DataGridControl.
    <xcdg:TableView.FixedHeaders>
    <DataTemplate>
    <xcdg:InsertionRow/>
    </DataTemplate>
    </xcdg:TableView.FixedHeaders>

    When I run the application I can see the DataGrid with data and also an extra row at the beginning.

    But When I edit cells in newly added row and press enter I get the following error.
    An attempt was made to add a new data item to a source that does not support insertion.

    Can anyone please help me?
    Thanks In Advance.
    Debkumar

    Imported from legacy forums. Posted by debkumar (had 7169 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Debkumar,

    When bound to an ItemsSource (People: ObservableCollection<Person> in your case), we rely on the IBindingList interface to determine whether or not Insertion is possible.

    If you implement the interface in your People collection, then Insertion will work without problems.

    The need for IBindingList might change in the future as we have already <a href=”http://forums.xceed.com/forums/ShowPost.aspx?PostID=5876″>received comments</a> to widen the list of supported interfaces.

    Let me know if you encounter more problems with Insertion.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 469 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks Marcus.

    Warm Regards
    Debkumar

    Imported from legacy forums. Posted by debkumar (had 538 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi

    From what I can tell if your class implements both IBindingList and ObservableCollection then the ability to insert a row will vary between assigning the class instance directly to the DataGridControl, or using a DataGridCollectionViewSource or DataGridCollectionView.

    Using DataGridCollectionViewSource or DataGridCollectionView will give the error as descibed in the initial post – with IBindingList never being tested for insertion.

    Assigning the source directly to the DataGridControl will invoke IBindingList for insertion.
    The problem however is you then lose control over what columns you want displayed.

    Imported from legacy forums. Posted by Nigel (had 889 views)

    Xceed Support
    Member
    Post count: 5658

    “The problem however is you then lose control over what columns you want displayed.”

    Although I usually tell clients to avoid it: You can set the AutoCreateColumns to false and add the columns to the Columns collection manually. This should only be used in the case where you cannot use the DataGridCollectionView[Source].

    Imported from legacy forums. Posted by Jenny [Xceed] (had 379 views)

    User (Old forums)
    Member
    Post count: 23064

    Is there any update on this? Implementing IBindingList is pretty painful with ObservableCollection interface and plus IBindingList is pretty archaic and was designed to work with Windows Forms.

    Imported from legacy forums. Posted by nat (had 461 views)

    User (Old forums)
    Member
    Post count: 23064

    Dear Xceed-WPF-Grid-Team,

    I agree in Nigel’s remarks…
    I have an observable collection and implemented IBindingList-interface to support a InsertionRow. But I am not able to add any data row to my collection.

    No methods of IBindingList-interface from my RowCollection is called.

    I have to use DataGridCollectionView-class to support Sorting & Grouping in my grid !!

    So the approach to bind ItemSource (=myRowCollection (= observableCollection & IBindingList-derived collection class)) directly to your DataGridControl will disable sorting & grouping support.

    Please increase priority for a better binding-solution with AllowAddNew !!!

    Thanks
    Dietmar

    Imported from legacy forums. Posted by Dietmar (had 720 views)

    User (Old forums)
    Member
    Post count: 23064

    I’ve noticed that it’s not ObservableCollection<T> that is causing an issue with the DataGridCollectionView[Source], but more specifically, it is the implementation of INotifyCollectionChanged.

    Everything works as expected when I bind the grid to something like this:

    public class SomeCollection : BindingList<SomeDataItem>
    {}

    However, if I implement the INotifyCollectionChanged interface then new items can no longer be added to the binding list:

    public class SomeCollection : BindingList<SomeDataItem>, INotifyCollectionChanged
    {}

    And as Nigel discovered, bypassing the DataGridCollectionView[Source] solves the problem but this obviously is not the desired solution. I’ve looked at the DataGridControl and associated classes in Reflector (not in detail, just a quick overview) and nothing has jumped out indicating why the CollectionChanged event specifically is “hiding” the IBindingList support from the DataGridControl.

    Imported from legacy forums. Posted by Kennie (had 579 views)

    User (Old forums)
    Member
    Post count: 23064

    Some changes were made in regards to this issue, you can obtain the fixe <a href=”http://download3.xceedsoft.com/Packages/3.2.7559.11410/XceedComponents.exe”>here</a&gt;

    Imported from legacy forums. Posted by Matt (had 7481 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.