HelloI Have a problem with refreshing winGrid.I bind data to the grid like this: private BindingSource bs; var employeeQuery = from employee in db.Employees orderby employee.LastName select employee; bs = new BindingSource(employeeQuery, ""); ultraGrid1.DataSource = bs;
The grid display all the data.When I change a value in a cell, and I want to refresh the grid so I will see the original data, the drid do not refresh itself, and I stiil see the new data i wrote.To refresh the grid I used: ultraGrid1.Rows.Refresh(Infragistics.Win.UltraWinGrid.RefreshRow.ReloadData);Thanks,Yossy
Hi Yossy,
When you make a change to a grid cell and then leave the cell, the data is saved to the grid's DataSource. So calling Refresh will not do anything. The grid will reload the data from the data source, but that has already been updated.
If the row is still in edit mode, and the user has not yet left the row, you might be able to get what you want by calling grid.ActiveRow.CancelUpdate.
If that doesn't work, then you will need to rely on your data source to undo the changes. I'm not sure if a LINQ datatable will do that.
In EF 4, there's a method on the data context that will restore the object (reload from the database):
context.Refresh(RefreshMode.StoreWins, myObject);
But...Here's my situation and it doesn't seem like I should have to call it:
In the grid, I click on a cell and change the value of that cell. I tab to the next cell, keep pressing escape until the pencil thingy disappears. The data in my row is not replaced with the original values -- unless, in the Before or After RowCancelUpdate event, I call the Refresh method on the data context.
I also tried calling BindingSource.CancelEdit() method, but the original values were not restored in the grid (or my object).
I was thinking that the grid wouldn't apply any values back to the binding source until I left the row. However, that's not what's happening. I set a breakpoint in the BeforeCancelRowUpdate event and my object has already been changed. And, as you said, I verified that it updates the binding source when you exit edit mode in the cell.
This doesn't seem right to me. Not all data can be completely validated at a single, cell level. Invidual cells may contain valid values, yet those values may not be valid in the context of the entire row. Unfortunately, since the data's already been given to the binding source, the objects are going to send property changed notifications to anyone whose listening. This means that invalid data could easily be passed around.
IMO, data shouldn't be given to the binding source until the user leaves the row.
Hi,
You can control when the grid writes changes to the data source using the UpdateMode property. By default, the grid writes the changes when you changes a cell or the grid loses focus. But you can set it to only update on a row change.