gpt4 book ai didi

vb.net - 模拟 DataGridView 中的标题单击

转载 作者:行者123 更新时间:2023-12-04 18:19:39 29 4
gpt4 key购买 nike

我正在尝试使用快捷键模拟 datagridview 第 1 列中的 headerclick,但我不知道如何。

Private Sub frm_lista_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.S And e.Alt Then
'this handler exists
DataGridView1_ColumnHeaderMouseClick(whathere, whathere)
End If
End Sub

有什么帮助吗?

最佳答案

确保表单具有此属性集:

Me.KeyPreview = True

由于您试图从键盘事件中指定第 1 列,因此您可以传递自己的事件参数:
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If ((Control.ModifierKeys And e.Alt) AndAlso e.KeyCode = Keys.S) Then
Dim mea As New MouseEventArgs(MouseButtons.None, -1, -1, -1, -1)
Dim dgvcme As New DataGridViewCellMouseEventArgs(1, -1, -1, -1, mea)
DataGridView1_ColumnHeaderMouseClick(DataGridView1, dgvcme)
End If
End Sub

该事件现在应该有 e.ColumnIndex属性集。
Private Sub DataGridView1_ColumnHeaderMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick
If e.ColumnIndex = 1 Then
MessageBox.Show("OK")
End If
End Sub

或者,您可以只从两个地方调用一个子例程:
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
If ((Control.ModifierKeys And e.Alt) AndAlso e.KeyCode = Keys.S) Then
Call HandelColumnOneClick()
End If
End Sub

Private Sub DataGridView1_ColumnHeaderMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick
If e.ColumnIndex = 1 Then
Call HandleColumnOneClick()
End If
End Sub

Private Sub HandleColumnOneClick()
'// Do Something
End Sub

关于vb.net - 模拟 DataGridView 中的标题单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10930884/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com