I've a problem with my DataGrid bound to a LINQ Expression. I've in fact two DataGrid bound to the same SQL table, using the same DataContext.
When I edit existing rows in one or the other grid, the changes are reflected to the other grid, and vice versa, as expected.
But when I insert a record or delete a record in one of the grid, changes are not reflected to the other grid. It is like new row are in a state where my LINQ expression does not take those type of changes.
I need to save the changes to the Database, before the other grid can "see" the changes.
Is there anyway for both LINQ result object can be notify of the Insert row/Delete row changes?
Here is my code:
public partial class Form1 : Form
{
GMR_DEVEntities CTX;
public Form1()
{
InitializeComponent();
CTX = new GMR_DEVEntities();
dataGridView1.AutoGenerateColumns = true;
dataGridView2.AutoGenerateColumns = true;
this.dataGridView1.Columns.Clear();
this.dataGridView2.Columns.Clear();
}
private void btnLoadGrid1_Click(object sender, EventArgs e)
{
var Data = from dd in CTX.tblConfigs select dd;
this.dataGridView1.DataSource = Data;
}
private void btnLoadGrid2_Click(object sender, EventArgs e)
{
var Data = from dd in CTX.tblConfigs select dd;
this.dataGridView2.DataSource = Data;
}
private void btnSave_Click(object sender, EventArgs e)
{
CTX.SaveChanges();
}
}
I've found a solution, that work good. The first Grid (dtgGrid )is attach to a BindingSource, witch is attach to a LINQ query result. Then the second grid (dtgFilteredGrid), is attach to another BindindSource witch is the result of LINQ query that filter the first BindingSource. Then when the user edit dtgFilterGrid, update are manually done to keep the the first BindingSource up to date.