Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 226
ProfK Avatar asked Mar 16 '12 04:03

ProfK


2 Answers

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;
like image 119
jaselg Avatar answered Nov 26 '22 11:11

jaselg


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.

like image 44
Maciej Avatar answered Nov 26 '22 11:11

Maciej