我有一个UltraGrid
,其中包含几列,如下所示:
------------------------
| Name | Year | Audit |
------------------------
| John | 2012 |[Button]|
------------------------
| Bill | 2013 |[Button]|
------------------------
我想在运行时使用键盘快捷键在所选行的审核列按钮上单击。那可能吗 ?像这样的东西(不存在)
myUltraGrid.ActiveRow.Cells("Audit").CellButton.PerformClick()
答案 0 :(得分:1)
点击Button Style
的单元格会触发事件ClickCellButton
。此事件接收包含单击的单元格的CellEventArgs
信息。您可以轻松地重构代码以分离在此事件中执行的操作,并使该操作可以从事件外部调用(无论何时需要执行操作)
' Your clickCellButton will be refactored to extract in a separate method '
' the action for every cell button'
Private Sub grd_ClickCellButton(sender as object, e as CellEventArgs)
Try
if e.Cell.Column.Key == "Audit" Then
ActionForCellAudit(e.Cell.Row)
elseif (e.Cell.Column.Key == "key2" Then
ActionForCellButton1()
elseif (e.Cell.Column.Key == "key3" Then
ActionForCellButton1()
Catch(a As Exception)
MessageBox.Show(x.Message)
End Try
End Sub
Private Sub ActionForCellAudit(row As UltraGridRow)
' The action required if clicking the Audit cell button is here'
End Sub
......
现在,当您需要在其他位置执行相同的操作时,您会提取有关ActiveRow
的信息并调用ActionForCellAudit
Private Sub Form1_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) _
Handles Form1.KeyDown
' Supposing the CTRL+F5 is the shortcut defined to execute the ActionForCellAudit
If e.KeyCode = Keys.F5 AndAlso e.Control = True then
if grd.ActiveRow IsNot Nothing AndAlso grd.ActiveRow.IsDataRow Then
ActionForCellAudit(grd.ActiveRow)
End If
End If
End Sub