Sometimes i want to move to a cell in the same activated row. For example if i am in a cell getting a product code i want:
1.- Move to another cell if the code is valid.
2.- Remain in the same cell if no the code is wrong.
I ussually write the code in BeforeCellDeactivate, look for the product, display the name in one cell, the price in another and so on. Then
i want to move to another cell o remain until a valid code is entered.
Wich is the best way to do this and is BeforeCellDeactivated the correct place to validate this product code?
The easiest way to move focus to a new cell is to simply set the ActiveCell property on the grid.
Which event you would use depends on when you want to move to the other cell. BeforeCellDeactivate will fire when the user tried to leave the current cell. So this doesn't seem like such a good idea to me, because if the user attempts to click from one cell onto a completely different cell in another row, then you will end up setting focus to a cell other than the one they clicked on and this might be pretty confusing to a user.
So the real question is, what criteria do you want to use to decide when to change the focus?
Setting the ActiveCell property in this event doesn't work. The real situation is that the user enter a product code and press Enter or Tab. At this moment i must look up for this code (if exists) and put its description and price (and perhaps other properties) to another cell. Then i must move
to another cell (in example the quantity cell).
When user press tab to leave one cell wich are the order and what events fires?. Could i prevent of moving that cell if is not validated?.
You can use beforeexiteditmode to validate input and if invalid set e.cancel = true to force back into entry. While inside this event use activecell.text or activecell.editorresolved.value for validation.
In afterexiteditmode you should be able to move to another cell either by setting activecell or doing some performaction's.
To force the new cell into edit mode you can use a performaction of entereditmode.
So why not just use a flag or the EventManager to prevent recursion.
I use the underlying DataRowView to read fields and in beforeexiteditmode this data is not available (so i must read it from the grid). If i use
activecell in BeforeCellDeactivate i get a recursive call.