In my (not binded) DataGridView some cells are editable, and some are not. When I click on an editable cell the focus goes there and i can write anything. Then, if i press the key TAB the focus goes to the next cell. But if the entered value is not valid, i can check the value from the event Grid_CellValidating and cancel the change using e.Cancel = True . If I do so, the focus stays in the same cell waiting for a valid value, instead of changing the current cell.
Until here all works as expected.
What I need now is, from a new modal window where I can select a value, set this value to a cell of the grid in the parent form and close the modal window.
This works, but I don't want just set the value to the cell. I want also to set the cell in "editing mode". I mean by "editing mode" that state where the cell content is selected and if you try to change the value, the event Grid_CellValidating fires and if the value is not valid, the logic in the Grid_CellValidating event can check it to decide if it's valid or not...
I didn't succeed with that. This is the code I'm trying to use to make it work.
myGrid.Rows(myGrid.Rows.Count - 1).Cells("EID").Value = 1
myGrid.Focus()
myGrid.CurrentCell = myGrid("EID", myGrid.Rows.Count - 1)
myGrid.BeginEdit(True)
But this definitely does not work.
In fact, the focus is not even on the Grid. I can see the value 1 in the cell but the focus is not there. For example, if I press the key TAB I can see that the focus is on another control, not in the Grid.
What I expect is: If the value 1 is not valid, the event CellValidating fires and do the work...
Do you know what should I do to get the behavior I need?