Cell End Edit および Selection Changed イベントのコードは次のとおりです。
Private Sub dvJOBranch_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dvJOBranch.CellEndEdit
'get the current column and row index
curCol = e.ColumnIndex
curRow = e.RowIndex
'if the cell is blank, set it to zero
If IsDBNull(dvJOBranch.Rows(curRow).Cells.Item(curCol).Value) Then
dvJOBranch.Rows(curRow).Cells.Item(curCol).Value = 0
'convert it to integer
Else
dvJOBranch.Rows(curRow).Cells.Item(curCol).Value = _
Convert.ToInt32(dvJOBranch.Rows(curRow).Cells.Item(curCol).Value.ToString())
End If
'if the user do mouseclick in datagridview
isMouseClick = dvJOBranch.Capture.ToString()
'if the user does not click any cell from the datagridview
If isMouseClick = False Then
isEdited = True
iColumnindex = e.ColumnIndex
irowindex = e.RowIndex
If dvJOBranch.CurrentRow.Index = dvJOBranch.RowCount - 1 Then
If dvJOBranch.CurrentCell.ColumnIndex < dvJOBranch.ColumnCount - 1 Then
dvJOBranch.CurrentCell = dvJOBranch.Item(iColumnindex + 1, irowindex)
End If
isEdited = False
End If
End If
End Sub
Private Sub dvJOBranch_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dvJOBranch.SelectionChanged
'if the user does not click any cell from the datagridview
If isMouseClick = False Then
If isEdited Then
If dvJOBranch.CurrentCell.ColumnIndex < dvJOBranch.ColumnCount - 1 Then
dvJOBranch.CurrentCell = dvJOBranch.Item(iColumnindex + 1, irowindex)
Else
dvJOBranch.CurrentCell = dvJOBranch.Item(2, irowindex + 1)
End If
isEdited = False
End If
End If
'set it to false
isMouseClick = False
End Sub
このコードの機能は、ENTER キーを使用して編集した後、現在のセルを右に移動することです。私のコードでは、エラーがあるため、ユーザーが任意のセルをクリックすると、マウス クリックもキャプチャします。マウス クリックをキャプチャしない場合、私は今やろうとしているのは、編集中に矢印キーをキャプチャすることです。たとえば、セルを編集した後、上矢印キーを押すと、上に移動するのではなく、ENTER キーの関数のように右に移動するためです。
どんな助けとガイドも感謝します、ありがとう