点击一个单元格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