I am using Entity Framework to communicate with an SQLServer database and am using WinGrid to view the database records. To edit, add or delete a record, I call up a separate detail form. If I am editing or deleting a record, when the changes are made, the WinGrid reflects the changes immediately and the altered record appears in the grid (or disappears in the case of a delete). When adding an new record, however, the record is not visible in the grid after performing a "SaveChanges()" command to save the new record to the database. If the program is closed and then restarted, the record appears in the grid as it should. I have tried every refresh command I can think of on all of the components, including the grid, the bindingsource and the EF components and nothing works to show the new record in the grid.
Any suggestions?
Hi Mike and Steve
I figured it out. It has nothing to do with the UltraGrid, as Steve already confirmed that it also doesn't work with GridView.
I searched for a while and came up with the following solution:
grdAccounts.DataSource = _dataContext.tblAccount.Execute(MergeOption.AppendOnly); grdAccounts.Refresh();
You need to call this if you bind the first time and after you added new rows.For deletes and updates refreshing the grid is sufficient.
Hope it helps.
cheersAndy
hi I have a better solution to your problem
when initially binding up with linq2sql;
BindingSource.DataSource = DataContext.YourTable.ToList()
you only have to do this once, if you connect your grid.DataSource to the BindingSource you can do DataContext.YourTable.Add(new Entity) and they show up.
Took me a while to figure out what was going on but saves cluttering code behind with work around code
Andy;
Your solution works in my program as well. I'm still not sure why all this is needed, but it does appear to work. I will continue to test it and make sure there are no "side effects".
Many thanks for working this problem out!
Steve