Back to Devexpress

RepositoryItemButtonEdit.ButtonPressed Event

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitembuttonedit-448d4308.md

latest4.3 KB
Original Source

RepositoryItemButtonEdit.ButtonPressed Event

Occurs when an edit button is pressed within a button editor.

Namespace : DevExpress.XtraEditors.Repository

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Events")]
public event ButtonPressedEventHandler ButtonPressed
vb
<DXCategory("Events")>
Public Event ButtonPressed As ButtonPressedEventHandler

Event Data

The ButtonPressed event's data class is ButtonPressedEventArgs. The following properties provide information specific to this event:

PropertyDescription
ButtonGets the button being pressed/clicked.

Remarks

You can handle the ButtonPressed event to response to pressing an editor button in a button edit control. The event occurs when the user presses a button but before releasing it. After the user presses and releases a button, the RepositoryItemButtonEdit.ButtonClick event is fired. When the user presses a button but releases it outside the button’s region, only the ButtonPressed event occurs.

Use the ButtonPressed event, for instance, to activate a dropdown window, a dialog, or to perform specific calculations based on a value entered, etc.

The sender parameter of an event handler represents the button edit control, whose button is being pressed. The button itself is identified by another event parameter (see the ButtonPressedEventArgs.Button property).

The editor’s ButtonEdit.ButtonPressed event is equivalent to the current event.

Example

The following code shows a ButtonEdit.ButtonPressed event handler for a button edit control.
When the end-user presses the first button (button with index 0), the handler activates a custom dialog of class Form2. The form’s constructor requires an edit value which will be edited in the dialog. After the form is successfully closed, the modified value is retrieved via the EditingValue property and assigned back to the editor’s edit value.

csharp
using DevExpress.XtraEditors.Controls;

private void buttonEdit1_ButtonPressed(object sender, ButtonPressedEventArgs e) {
    ButtonEdit editor = (ButtonEdit)sender;
    int buttonIndex = editor.Properties.Buttons.IndexOf(e.Button);
    if (buttonIndex == 0) {
      using(var form = new Form2(editor.EditValue)) {
          if(form.ShowDialog(this) == DialogResult.OK)
              editor.EditValue = form.EditingValue;
      }
    }
}
vb
Private Sub ButtonEdit1_ButtonPressed(ByVal sender As Object, _
 ByVal e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) _
 Handles ButtonEdit1.ButtonPressed
    Dim Editor As ButtonEdit = CType(sender, ButtonEdit)
    Dim buttonIndex As Integer = Editor.Properties.Buttons.IndexOf(e.Button)
    If buttonIndex = 0 Then
        Using form = New Form2(editor.EditValue)
            If form.ShowDialog(Me) = DialogResult.OK Then
                editor.EditValue = form.EditingValue
            End If
        End Using
    End If
End Sub

See Also

ButtonPressed

ButtonClick

RepositoryItemButtonEdit Class

RepositoryItemButtonEdit Members

DevExpress.XtraEditors.Repository Namespace