在gridview中单击RepositoryItemButtonEdit的按钮不会在DevExpress中触发任何事件

时间:2015-06-25 15:29:04

标签: vb.net devexpress

我有一个包含多行3列的gridview。前两列包含客户端的ID号和 客户的名字。第三列是RepositoryItemButtonEdit按钮,单击该按钮时将从中删除客户端 那一行。

我已按以下方式宣布RepositoryItemButtonEdit

Dim WithEvents buttonDelete As RepositoryItemButtonEdit
buttonDelete = New RepositoryItemButtonEdit

buttonDelete.TextEditStyle = TextEditStyles.HideTextEditor
buttonDelete.Buttons(0).Kind = ButtonPredefines.Glyph
buttonDelete.Buttons(0).Caption = "Supprimer"
AddHandler buttonDelete.Click, AddressOf Me.Button_Click

我已按以下方式将其添加到第三列。

Dim unbColumn As GridColumn = gvException.Columns.AddField("Delete")
                unbColumn.VisibleIndex = gvException.Columns.Count
                unbColumn.ColumnEdit = buttonDelete
                gvException.OptionsView.ShowButtonMode = DevExpress.XtraGrid.Views.Base.ShowButtonModeEnum.ShowAlways

以下列方式捕获“按钮点击”事件:

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles buttonDelete.Click 
    MessageBox.Show("Hello world")
end sub

当我启动应用程序时,我会看到每行的“删除”按钮。

问题:但是,我只收到一个“Hello World”消息框 当我点击第一行的“删除”按钮时,而不是单击其他行中的“删除”按钮。

1 个答案:

答案 0 :(得分:0)

添加 buttonDelete.ButtonPressed 事件,而非 buttonDelete.Click 事件。

我尝试过的是下面的工作正常:

Dim buttonDelete As New RepositoryItemButtonEdit

buttonDelete.Buttons.Clear()
buttonDelete.ButtonsStyle = BorderStyles.UltraFlat
buttonDelete.TextEditStyle = TextEditStyles.HideTextEditor

Dim edtrBtn As EditorButton = New EditorButton()
edtrBtn.Kind = ButtonPredefines.Glyph
edtrBtn.Caption = "Supprimer"

AddHandler buttonDelete.ButtonPressed, AddressOf RepositoryItemButtonEdit_Pressed

buttonDelete.Buttons.Add(edtrBtn)

按下事件:

Private Sub RepositoryItemButtonEdit_Pressed(sender As Object, e As ButtonPressedEventArgs)

''' Your Logic Here

End Sub

它应该工作。休息没问题。