Hi,
I am using UltraWinGrid which contains a boolean column. So each cells is displayed correctly as a checkbox.
The grid data is handled by a binding object.
When the user clicks on a cell, the checkbox is checked or unchecked as expected. But my data object is notified of a CellValueChanged only when the user clicks outside of the grid.
There is any way to handles the checkbox clicks or state changed to force a data update ?
I tried to handle the CellChange event and, if it is a checkbox cell, force an exit of the edit mode. But it doesn't work as expected, it blocks the native checkbox behavior...
Best regards,
Jean-Charles Durand
You could do this:
private void ultraGrid1_CellChange(object sender, CellEventArgs e) { if (e.Cell.Column.DataType == typeof(bool)) { e.Cell.Row.Update(); } }
But this may not be ideal, because it will commit any changes in the entire row.
Another option would be to just get the new value of the cell inside the CellChange event and use it for whatever you need, without updating the data source.But to do that, you have to use the Text property of the cell.
private void ultraGrid1_CellChange(object sender, CellEventArgs e) { if (e.Cell.Column.DataType == typeof(bool)) { bool newValue = bool.Parse(e.Cell.Text); Debug.WriteLine(newValue); } }
Another option that seems to work is to force the grid to exit edit mode:
private void ultraGrid1_CellChange(object sender, CellEventArgs e) { if (e.Cell.Column.DataType == typeof(bool)) { grid.PerformAction(UltraGridAction.ExitEditMode); } }
That is forcing the cell to write its value back to the underlying datasource, but does not cause a full row update (which avoids a DB commit if the update causes the BO to save to the DB and also avoids the invalid data popup being shown if the record is not currently valid).
Really though, the solution to this seems to be for cells to have the Advanced Binding 'Data Source Update Mode' options of OnPropertyChanged and OnValidation like the non-grid controls have. There are a lot of cases where you want the cell to commit its change straight back to the BO rather than waiting for a cell change/etc.
Thanks guys !
I will try all of these solutions.
@Mike: the second one might be the best, but in my case, I how to force an update of the data binding... So maybe I will have to update all the row.
I will keep you aware of what I choose.
Best regards.