7

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?

ProfK
  • 49,207
  • 121
  • 399
  • 775

3 Answers3

6

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;
jaselg
  • 367
  • 3
  • 10
  • 3
    That works, thanks, but it's a bit brain dead to me that nothing else, including the `RefreshDataSource` method, works. DevExpress controls seem to lag a bit behind with ED data sources. – ProfK Mar 16 '12 at 08:43
  • In my opinion, a gridview does nothing else but displays the data. A programmer should tell it the data source has changed, so that it can re-display the data. I don't know whether DevExpress has this feature or not, or we should do it manually. – jaselg Mar 16 '12 at 11:46
2

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.

Maciej
  • 2,175
  • 1
  • 18
  • 29
  • In one of our projects this does not work (it is a grid with subcolumns. AddRemove normally works except - user clicks on something to sort - afterwards gridview does no further updates...) – Offler Jan 29 '14 at 12:18
0

I suggest you try this

clientListBindingSource.ResetBindings(False);

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