(linq) datagridview population

  • Thread starter Thread starter LT
  • Start date Start date
L

LT

Hi everybody,
I'm filling a datagridview taking data from a db table in the following
way:

-------------------------------------------------------------------
DataClasses1DataContext Ddc = new DataClasses1DataContext();
listaDataGridView.DataSource = Ddc.GetTable<Table>();
-------------------------------------------------------------------

Then I do insertion operations:

-------------------------------------------------------------------
Table table = new Table
{
Code = code,
Description = description
};
Ddc.Table.InsertOnSubmit(table);
Ddc.SubmitChanges();
-------------------------------------------------------------------

and updations:

-------------------------------------------------------------------
Table tab = Ddc.Table.Where(c => c.ID == id).First();
tab.Codice = code;
tab.Descrizione = description;
Ddc.SubmitChanges();
-------------------------------------------------------------------


This is the datagridview refresh :

-------------------------------------------------------------------
Ddc.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues,
Ddc.Table);
-------------------------------------------------------------------


The problem is that inserted rows are not viewed until the next opening
of the form.
This is partially solved if I use:
-------------------------------------------------------------------
DataClasses1DataContext Ddc = new DataClasses1DataContext();
listaDataGridView.DataSource = Ddc.Table.ToArray();
-------------------------------------------------------------------

But in this way the datagridview don't let me to order columns anymore.

Can someone help me?

Thanks and Regards,
Luigi
 
Rather than bind to the table itself, try using GetNewBindingList() on
the table; this should give you more binding support. I remember posting
a bespoke binding-list implementation for DataContext (to this list),
which might also be of use.

Marc
[C# MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top