BindingList bound to GridView

2 posts, 0 answers
  1. David Simmonds
    David Simmonds avatar
    56 posts
    Member since:
    Mar 2010

    Posted 10 Jan 2012 Link to this post

    I have a BindingList bound to a GridView. I can make changes to the grid which are reflected back into the BindingList. The BindingList is filled from a linq result set. How do I move the changes in the BindingList back to the database?

    TRACKING[] data = (from t in context.TRACKINGs
                       where SqlMethods.Like(t.EHT_ISO_DWG, "%02-02%")
                       select t).ToArray();
    return new BindingList<TRACKING>(data);

    The above code is what is used to fill the BindingList. The return value is the set to the DataSource property of the GridView.
  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 13 Jan 2012 Link to this post

    Hi David,

    You can use the InsertOrSubmit API of your data context object to save the changes and the inserted data. Here is a simple example using your codebase:
    //read...
    TRACKING[] data = (from t in context.TRACKINGs
                       where SqlMethods.Like(t.EHT_ISO_DWG, "%02-02%")
                       select t).ToArray();
    radGridView1.DataSource = BindingList<TRACKING>(data);
     
     
    //write...
     
    BindingList<TRACKING> list = (BindingList<TRACKING>)radGridView1.DataSource;
    foreach (var item in list)
    {
       context.TRACKINGs.InsertOnSubmit(item);
    }

    More information about CRUD using LINQ and Entity framework you can find in this article.

    I hope this helps. Let me know if you need further assistance.

    Regards,
    Julian Benkov
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Back to Top