Hi
I have an ultracombo column on a grid. When I do the grids PerformAction(UltraGridAction.UndoCell) it does not set the combo item back to it's original value. Although, the value of the cell is set back to its original value when I look in code. For example:
I have a drop down with value like so
Value Member : Display Member
1 : One
2 : Two
say the value in the cell is currently 1 so the display reads One, I then choose Two but I have code to cancel that and also PerformAction(UndoCell) , what happens then is the cell shows value 1 but text 2 i.e:
1 : Two
How do I undo it properly?
Thanks
Paul
The undo operation has to occur while the cell is in edit mode since the grid does not keep track of these changes.
The best place to validate a cell is hooking cellchange. Alternatively you can just call e.Cell.CancelUpdate. eg. private void UltraGrid1_CellChange(object sender, CellEventArgs e) { if ((string)e.Cell.Text == "B") { e.Cell.CancelUpdate();
orultraGrid1.PerformAction(UltraGridAction.UndoCell); } }
Hi Michael
I was advised to do that in Before Exit Edit.
So, I am still in edit mode and both the choices above don't work when the cell is a combo, they work when it is just plain text. I have written some workaround to put the combo back to what it was. The first line below resets the cell value but the combo would stay on whatever the user had selected prior to UndoCell so I have to then set it back to what it was myself.
this.Grid.PerformAction(UltraGridAction.UndoCell); // Reset cell value if (args.Cell.EditorResolved is UltraGridComboEditor) args.Cell.EditorResolved.Value = args.Cell.Value; // undo doesn't work on combos so have to reset manually e.Cancel = true; // do not leave
If I get no further problems with it then i will probably just leave it as it is but it seems to me that it does not work like it should do.
BeforeExitEditMode event doesn't expose the cell as an event argument. That is why it's much easier to use CellChange.
Paul Syvret said:There are statuses for example whereby we show a pop up after the user changes it to explain what will happen once the change is made, one of the answers they can choose is "no, just leave it as it is".
That makes sense. That also might explain why it works for you in some cases, and it also might make things more complicated. My solution may not work in that case.
Because, once you show a dialog, the grid is going to lose focus, which might make it try to edit edit mode again - while you are already inside BeforeExitEditMode. So that can get you into a vicious cycle. I'm not sure if the event fires recursively in that case or not, but showing a dialog inside that even can be very tricky. Let me know if my solution doesn't work in your app. We may have to find another way.
Hi Mike,
Thanks for clarifying. I will do this for undoing and resetting.
Just to give an example of why we reset the values sometimes. There are statuses for example whereby we show a pop up after the user changes it to explain what will happen once the change is made, one of the answers they can choose is "no, just leave it as it is".
Thanks for helping out.
Hi,
Just to clarify and make sure I understand the issue...
You are handling the grid's BeforeExitEditMode event and validating the current Text in the cell. Your validation is apparently checking for duplicate values in every row - but that's not really relevant to the issue. If the text is invalid, for whatever reason, you are calling PeformAction(Undo) to revert the cell to the original value?
That seems a little odd, since the user might not want the original value - they might want something else, or to fix what they entered.
In any case, I tried this out using a cell with an UltraCombo, a cell with an UltraDropDown, and just a plain text cell, and the Undo action doesn't seem to do what you want (or do anything at all really) in any of these cases. You seem to be saying it works for a normal text cell, but it's not working for my sample even in that case.
PerformAction is really intended to allow you to simulate user interaction with the grid. So I'm not sure it's a good idea to use it like this while the cell is in edit mode, anyway.
Anyway... as you noticed, the Value of the cell does not get updated until the user commits the change to the cell. Value reads from the underlying data source. So that means you always have the original value available and don't really need to do any extra work to store it. So I was able to get it to work by setting the editor's value to the original value of the cell. This works for both Combo and non-combo (plain text) cells in my testing.
Here's the relevant code and my sample project.
private void UltraGrid1_BeforeExitEditMode(object sender, Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs e) { var grid = (UltraGrid)sender; var activeCell = grid.ActiveCell; if (false == IsTextValid(activeCell)) { activeCell.EditorResolved.Value = activeCell.Value; e.Cancel = true; } }
WindowsFormsApp36.zip
I don't want to check user input on every keystroke though, I want to check it when they are done editing. For example, if I need to check the user has not input a value in a cell that is not the same value as that cell in another row. I need to check the database to ensure this is not the case. I don't want that test happening every time the user presses a key.
Besides, this has completely detracted from the initial problem that the undo does not work on a cell with an ultracombo, it only appears to be working when it is text, or possible dates and so on, but not when an ultracombo.
I have made a workaround for this storing the original value before the user edits then checking it after they are done editing and reverting back in code where necessary. That does what I want without changing and retesting all the work so far which is based upon other answers in the forums stating to use BeforeExitEdit.
Maybe you could try out the undo on a combo in the grid and see if it does work but other than that I am closing this one.
Thanks for your help
Hello Paul,
BeforeExitEditMode doesn't fire until you attempt to leave the cell which isn't as efficient as CellChange which essentially fires on key stroke. That way you can call Undo when ever you the text isn't suitable before the end user tabs or clicks out of the cell.