ProfK
ProfK

Reputation: 51063

XtraGrid not refreshing after updates to its data 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?

Upvotes: 7

Views: 21729

Answers (3)

Bond Zini
Bond Zini

Reputation: 1

I suggest you try this

clientListBindingSource.ResetBindings(False);

It's supposed to refresh the binding source thereby refreshing the grid

Upvotes: 0

Maciej
Maciej

Reputation: 2185

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.

Upvotes: 2

jaselg
jaselg

Reputation: 377

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;

Upvotes: 6

Related Questions