1

我有UltraGrid几列看起来像这样:

------------------------
| Name | Year | Audit  |
------------------------
| John | 2012 |[Button]|
------------------------
| Bill | 2013 |[Button]|
------------------------

我想在运行时使用键盘快捷键单击所选行的 Audit 列按钮。那可能吗 ?像这样的东西(不存在)

myUltraGrid.ActiveRow.Cells("Audit").CellButton.PerformClick()
4

1 回答 1

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
于 2013-04-11T13:31:26.807 回答