I have an XtraGrid control on a windows form, bound to an object set as follows:
clientListBindingSource.DataSource = ObjectContext.Clients;
Where ObjectContext is a normal EF context. To edit a client, I pass the selected row's Client
object to my edit form, and get save changes as follows:
var rows = mainView.GetSelectedRows();
var editClient = ((Client)mainView.GetRow(rows[0]));
var editForm = new ClientDetailForm
{
EditClient = editClient
};
var result = editForm.ShowDialog();
if (result == DialogResult.OK)
{
ObjectContext.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
clientGrid.RefreshDataSource();
}
Changes I make in the edit form persist to the DB, but I have tried several ways of trying to get the grid to update, and it stubbornly refuses until I restart the application. What am I doing wrong?
Try to reset your data source after making changes like this:
yourGrid.DataSource = null; // you might not need this, but it's my practice
yourGrid.DataSource = data_source;
I found that a call to
Grid.RefreshDataSource();
works as expected if you are binding the DataSource via code like so:
IndicationSummaryGrid.DataBindings.Add("DataSource", Presenter, "SummaryDetailList", true, DataSourceUpdateMode.OnPropertyChanged);
Where "DataSource" is the grid property being bound, Presenter is the object being bound and SummaryDetailList is a list of objects belonging to Presenter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With