Clicking on a cell of Button Style
triggers the event ClickCellButton
. This event receives the CellEventArgs
containing information about the cell clicked. You could easily refactor your code to separate the action executed in this event and make that action callable from outside the event (whenever you need to execute the action)
' 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
......
Now when you need to execute the same action elsewhere you extract the info about the ActiveRow
and call the 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