2017-08-02 6 views
0

私は潜在的に謝罪したいと思います。Visual Basic - DataGridViewを実行するために入力CellContentClick

DataGridViewには、SELECTステートメントによって情報が取り込まれた状態で読み込まれます。ビュー内の特定のセルをクリックすると、新しいフォームが読み込まれます。しかし、私は、クリックから "ENTER"のキーを押すまでに変更できる方法があるかどうかを知りたいと思います。

私は自分のコードを添付しましたが、うまくいけば、これは役に立ちます。

の.NET Frameworkでも、私は、Visual Studio 2015を使用しています、事前に

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown 
    If e.KeyCode = Keys.Enter Then ' not sure on code here 
End Sub 

Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick 
    If Update_Detail.Visible = True Then Update_Detail.Close() 
    Dim istat As Object 
    If e.RowIndex > -1 Then istat = DataGridView1.Rows(e.RowIndex).Cells(0).Value 
    If e.ColumnIndex < 1 And e.RowIndex > -1 Then Update_Detail.TextBox1.Text = istat 
    If e.ColumnIndex < 1 And e.RowIndex > -1 Then Update_Detail.Show() 
End Sub 

をありがとう4.5.2

+0

あなたは 'vb.net'を使用している場合には必要ありません'VBA'タグも含まれています。 – braX

+0

ありがとうございます - これは削除されました。 – user3482471

+0

グリッドにKey_Downイベントがあります。あなたはこれを使うことができます。 – SQLAndOtherStuffGuy

答えて

1
Private Sub DataGridView1_KeyDown(sender As Object, e As KeyEventArgs) Handles DataGridView1.KeyDown 
     If e.KeyCode = Keys.Enter Then 

      Dim currentRowIndex As Integer = DataGridView1.CurrentCell.RowIndex 
      Dim currentColumnIndex As Integer = DataGridView1.CurrentCell.ColumnIndex 


      Dim istat As Object 

      If currentRowIndex > -1 Then istat = DataGridView1.Rows(currentRowIndex).Cells(0).Value 
      If currentColumnIndex < 1 And currentRowIndex > -1 Then Update_Detail.TextBox1.Text = istat 
      If currentColumnIndex < 1 And currentRowIndex > -1 Then Update_Detail.Show() 

     End If 

    End Sub 
+0

同じコードがForm_KeyDownイベントで機能します。 – SQLAndOtherStuffGuy

+0

こんにちは - それは素晴らしい作品です。しかしもう1つのこと - 私が押しているときには、行に行くという機能も維持しています。あなたはこれをオフにする能力を認識していますか? – user3482471

+0

問題ありません。潜在的な解決策についてはこちらをご覧ください。 https://stackoverflow.com/questions/26096968/preventing-windows-forms-datagridview-moving-to-next-row-on-pressing-enter-key。あなたは追加しようとすることができます。最後に 'e.SupressKeyPress = True'を返します。私はそれを試していない。 – SQLAndOtherStuffGuy

関連する問題