Hi,
I have a problem that happens sometimes, and I can't find the source of the problem:
In the software I develope:
1. I open a screen for the first time2. I change a cell in a grid of type dropDownList3. I try to save with SubmitChanges()
and the change is not saved!!!
I work with LINQ.
Waiting for your advise,Thanks ahead,Yael
What triggers the save? My guess is that you are using a toolbar button or some other control that does not take focus. Since the grid never loses focus, the changes in the current cell still in edit mode are not saved to the grid.
You can usually get around this by using the grid's PerformAction method to ExitEditMode and then perhaps also call grid.UpdateData to commit the current changes before you try to save.
Before "Save", I did the following:
1. set the focus on another control.
2. myGrid.PerformAction(UltraGridAction.ExitEditMode);
3. myGrid.UpdateData();
Still my change was not saved :(
What exactly do you mean by "save" here?
There are two layers of saving. The first is the grid writing the data to it's underlying DataSource.
The second is that data source writing it's changes to the back end.
The grid only deals with the former, it has no part in the latter. So are you saying that the grid is losing the changes and not saving them to the data source? If you simply tab away from the cell where you made the change, does the grid cell revert to the old value?
If I tab away, the new value is still in the grid.
I debugged, and saw that the grid and its binding source contains the new value.
I think that the problem is that when I do SubmitChanges(), it doesn't recognize the change -
m_hDBMinhal.GetChangeSet() returned {Inserts: 0, Deletes: 0, Updates: 0}
Okay... if the change is being written to the grid's DataSource, then either the DataSource is not recognizing the change for some reason, or else something else in your code already accepted the changes and it thinks the update has already completed.
What kind of DataSource are you using for your grid?
If it's a DataSet or a DataTable, then this should work. The only way I can think of that it would not work is if something in your code is calling AcceptChanges (or perhaps Cancel) on the data source before you try to get the changes.
I work with LINQ, so I don't use AcceptChanges etc.
We use dataContext.SubmitChanges() in order to save the changes.
As I wrote before, the dataContext.GetChangeSet() returns no changes.... :(
Hi Yael,
There's no reason why the RowSizing property should have any effect on saving the data.
After considerable efforts, I found what causes the problem:
In the initialize_layout event of the grid, I wrote this line:
this.DisplayLayout.Override.RowSizing = RowSizing.AutoFixed;
After I commented this line, the grid was saved with no problem!
I have no clue how this line caused the problem, but now it works fine.If you have an idea I would like to hear!
Thanks,Yael
I use a binding source in my code.
I debugged some more, and found this:
I made a change in a cell in the grid, and in the grid_cellChange event:
The binding source was updated, but the dataContext.getChangeSet() returned no changes!
--> Means that the dataContext did not track the change of the binding source!
Note that this happens only in the first time, if I'll insert now a row to the grid for example, the getChangeSet() will return 1 insert.
I'm not an expect on LINQ, but it probably depends on what kind of LINQ you are using, what it's returning, and what you are using as the DataSource of the grid.
The grid can only update the local data source using the BindingManager and the IBindingList or IList interface. The DataSource itself is responsible for tracking changes (if it wants to do so).
When using LINQ, I have often found that (depending on what type of LINQ you are using and where the data is coming from) that you can often get it to work better by wrapping the data source in a BindingSource.
In some cases, binding directly to data retrieved from LINQ won't work at all and you have to copy the data into some other structure more suitable for binding.