PNRT
asked on
VB.Net Datagridview - Return to edited cell
Hi Experts. On CeIlEndEdit I am trying to check the number of digits in the cell and if incorrect get the focus back to the cell so that the next key pressed appears in the cell to be corrected. It works sometimes but most times the next key pressed appears in the cell that was selected after leaving the first cell. Any help would be appreciated.
Relevantcell = DataGridView2.CurrentCell
If DataGridView2.CurrentCell. ColumnInde x = 2 Then
If Relevantcell.FormattedValu e.ToString .Length < 10 Then
MsgBox("The number is too short")
DataGridView2.CurrentCell = Relevantcell
DataGridView2.BeginEdit(Tr ue)
Exit Sub
End If
End If
Relevantcell = DataGridView2.CurrentCell
If DataGridView2.CurrentCell.
If Relevantcell.FormattedValu
MsgBox("The number is too short")
DataGridView2.CurrentCell = Relevantcell
DataGridView2.BeginEdit(Tr
Exit Sub
End If
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Actually CodeCruiser was correct - for your task you need validating event and setting e.Cancel=True to continue editing same cell
ASKER
Dim Relevantcell As DataGridViewCell
Relevantcell = CType(sender, DataGridView).Rows(e.RowIn
If DataGridView2.CurrentCell.
If Relevantcell.FormattedValu
MsgBox("The number is too short")
DataGridView2.CurrentCell = Relevantcell
DataGridView2.BeginEdit(Tr
Exit Sub
End If
End If