Hi, everyone,
Now I use a WinGrid to display data, the data is stored in a DataTable, and I register the
ultraDataSource1.CellDataRequested event, when this event is fired, I get data from the
DataTable, like below:
{if (e.Row.Band.Key == "RootBand" && e.Row.Index < _datatable.Rows.Count)
e.Data = _datatable.Rows[e.Row.Index][0];
break;}
}
now my question is: the user may make multiple changes from the UI(the WinGrid), and he/she wants to apply the changes
at one time, and there is a indicator to indicate that some changes have been made, but the user
has not applied it yet, anyone knows how to achieve this? Any help would be appreciated.
Thanks in advance.
Hi, Mike,
Thank you for your reply. please see 2 solutions below:
1. this.ultraGrid1.DataSource = dt; here dt is a DataTable, suppose there are 2 buttons, "Apply changes" and "Discard changes",
when the "Apply changes" button is clicked, I call "dt.AcceptChanges();",then the changes are saved to the dt; if I click
"Discard changes", I call "dt.RejectChanges();",then all the changes are discarded, and the ultraGrid displays its original data.
That works well.
2. Otherwise, if I set this.ultraGrid1.DataSource = this.ultraDataSource1, then use the "CellDataRequested" event to load data OnDemand from some other datasource, I set the UpdateMode
to Infragistics.Win.UltraWinGrid.UpdateMode.OnUpdate, and in the "ultraGrid1_BeforeRowUpdate" event, I set e.Cancel = true,
when I click the "Discard changes" button, I call "this.ultraGrid1.UpdateData()", then the "ultraGrid1_BeforeRowUpdate" event is fired
specified times according to how many rows were updated. but at last, I can only see the last row's data is reverted on the grid, not all
the rows, why? or I missed something?
Meanwhile, Are there some demos by using the "CellDataRequested" event, and show how to discard or save all changes?
Thank you very much!
Okay... you caught me. I admit it. I'm really a bot. :)
By default, the UpdateMode property of the grid is set to commit changes when the grid loses focus. So if you click on a button on the form, the grid will automatically save the changes to the data source - you don't have to do anything.
If this is a toolbar button, instead of a regular button, then it probably does not take focus. Therefore the grid would not lose focus, so no update will take place. In that case, you would call the grid.UpdateData method to commit the changes.
Hi, Mike and Torrey,
Thanks for your reply.
You know that I use the winGrid to display data, and the user can modify the data directly from the cells.
if the user edits the cells' data, there will be a indicator indicates that the data was changed, and I'd like to
use a button named "Apply changes", then if the users clicks this button, all changes were saved to the DataTable
or other DataSource.
Mike reminds me of that ALICE bot in that reply. :-P
Would the information at this link be helpful to you? It has information about getting the changed rows from a DataTable.
Hi,
I'm afraid I do not understand your question. Can you explain in more detail?