Visual Basic - 输入执行 DataGridView CellContentClick
Visual Basic - Enter to Perform DataGridView CellContentClick
首先,我想道歉,因为我是 Visual Basic(自学)的新手,所以我的一些代码可能看起来很奇怪。
我加载了一个包含由 SELECT 语句填充的信息的 DataGridView,当我单击视图中的某个单元格时,它会加载一个新的表单,这很好。但是我想知道是否有一种方法可以将单击更改为 "ENTER".
的按键
我已附上我的代码,希望这对您有所帮助。
提前致谢
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
我也在使用 Visual Studio 2015 和 .Net Framework 4.5.2
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
首先,我想道歉,因为我是 Visual Basic(自学)的新手,所以我的一些代码可能看起来很奇怪。
我加载了一个包含由 SELECT 语句填充的信息的 DataGridView,当我单击视图中的某个单元格时,它会加载一个新的表单,这很好。但是我想知道是否有一种方法可以将单击更改为 "ENTER".
的按键我已附上我的代码,希望这对您有所帮助。
提前致谢
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
我也在使用 Visual Studio 2015 和 .Net Framework 4.5.2
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