For more clear I recorded short video how it work www.8080.pl/download/dgv.wmv
I have radgridview with a datasource that is linking to a linq2sql:
When I insert a new record I want refresh the grid again:
But I see only error.
If I call if from button's event and it work correctly:
But I need automatic refresh after I added records. How and where I can do it?
I have radgridview with a datasource that is linking to a linq2sql:
| TestowaBazaDataContext db = new TestowaBazaDataContext(); |
| radGridView1.DataSource = db.tabelaZlecenias; |
When I insert a new record I want refresh the grid again:
| private void radGridView1_RowsChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e) | ||
| { | ||
| TestowaBazaDataContext db = new TestowaBazaDataContext(); | ||
| if ((e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.ItemChanged) && | ||
| ((int) radGridView1.Rows[e.NewStartingIndex].Cells["idZlecenia"].Value == 0)) | ||
| { | ||
| //new record | ||
| if (radGridView1.Rows[e.NewStartingIndex].Cells["Zlecenie"].Value != null) | ||
| { | ||
| var nowa = new tabelaZlecenia() | ||
| { | ||
| Zlecenie = (int) radGridView1.Rows[e.NewStartingIndex].Cells["Zlecenie"].Value | ||
| }; | ||
| db.tabelaZlecenias.InsertOnSubmit(nowa); | ||
db.SubmitChanges();
|
||
| } | ||
| } | ||
| } |
But I see only error.
If I call if from button's event and it work correctly:
| private void button1_Click(object sender, EventArgs e) |
| { |
| //I need refresh data by Linq in radGridView1 |
| TestowaBazaDataContext dbZ = new TestowaBazaDataContext(); |
| radGridView1.DataSource = dbZ.tabelaZlecenias; |
| } |
But I need automatic refresh after I added records. How and where I can do it?