This is a migrated thread and some comments may be shown as answers.

BindingList bound to GridView

1 Answer 61 Views
GridView
This is a migrated thread and some comments may be shown as answers.
David Simmonds
Top achievements
Rank 1
David Simmonds asked on 10 Jan 2012, 07:24 PM
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.

1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 13 Jan 2012, 01:21 PM
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).

Tags
GridView
Asked by
David Simmonds
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or