我的dgview中有一个列只能包含double值,我将代码放在 CellEndEdit 事件中。如果输入的值不是双精度,则将选择单元格并开始编辑
Dim flag_cell_edited As Boolean
Dim currentRow As Integer
Dim currentColumn As Integer
flag_cell_edited = True
currentColumn = e.ColumnIndex
currentRow = e.RowIndex
If e.ColumnIndex = 2 Then
If Double.TryParse(dgView.CurrentCell.Value, Nothing) Then
Else
MsgBox("Invalid Value")
'dgView.CurrentCell = dgItems(currentColumn, currentRow) 'Does not select the cell
'------------------
'This next 3 lines of code works for selecting the cell and beginning
'Edit but when I type, it appears on the cell the was focused after editing
'dgView.Rows(currentRow).Cells(currentColumn).Selected = True
'dgView.Rows(currentRow).Cells(currentColumn).Value = vbNullString
'dgView.BeginEdit(True)
End If
End If
这就是我所拥有的,如果我使用不是双倍的值编辑Rows(0).Cells(2)
,则点击说Rows(1).Cells(0)
它将选择返回到Rows(0).Cells(2)
,删除该值然后开始编辑。当我输入内容时,它会显示在Rows(1).Cells(0)
而不是Rows(0).Cells(2)