XtraGrid not refreshing after updates to its data source

ProfK picture ProfK · Mar 16, 2012 · Viewed 20.8k times · Source

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?

Answer

jaselg picture jaselg · Mar 16, 2012

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;