Home Forums WPF controls Xceed DataGrid for WPF How to insert a new row using a LINQ result as a data source

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

    Hi All,

    My problem is, that I get an exception all the time, when i try to add a new row using the built in GUI functionality of the DataGrid (WPF version), which says: the underlaying data source doesn’t support insertion.
    I used LINQ to SQL for geting the data from the DB and I proiveded the result directly as ItemSource, which worked fine, all the rows are shown correctly, can be edited and persisted into the DB using LINQ again, only the new row can’t be added 🙁

    I’m not sure, where the problem is.
    Maybe it’s
    – in the DataGrid or in some settings of it
    – in the way I bind it to the data source
    – in the data source

    What I miss is: where can I define the so called template for the new item (not visualy, but at code level, so the class initialization), at least somewhere I have to be able to provide a type to the DataGrid wich has a parameterless constructor.

    Any suggestions are welcome!

    Sorry for that, if this topic has been already written somewhere, in this case a link whould be a big help for me!

    Thx in advance
    BBL

    Imported from legacy forums. Posted by László (had 2667 views)

    Xceed Support
    Member
    Post count: 5658

    Insertion is currently only supported if the data source implements IBindingList. That said, use the GetNewBindingList method on the result returned from the query and bind to that list instead.

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

    User (Old forums)
    Member
    Post count: 23064

    Thx, it helped!

    Interesting, that it automaticaly filled the PK key field with value 0 (the PK column’s type is integer), and didn’t leave it as empty (null), but after saving it, the row has been refreshed to the correct IDENTITY field value geven by the SQL server…

    BBL

    Imported from legacy forums. Posted by László (had 2743 views)

    User (Old forums)
    Member
    Post count: 23064

    I was having the same problem.  I fallowed your instruction, but I’m still having a problem.  I can insert a row and the PK_Id show automaticly 0.  But can not edit the others fields.  I’m using VB

     

    Private db As New LinqSQLDataContext

    Private Sub Principal_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded

    Dim b As New Binding

    Dim l As New DataGridCollectionView(db.Table1.GetNewBindingList)

    b.Source = l

    Me.DataGridControl1.SetBinding(DataGridControl.ItemsSourceProperty, b)

    End Sub

    Imported from legacy forums. Posted by Etienne (had 2397 views)

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