Back to Devexpress

AccordionControl.ElementClick Event

windowsforms-devexpress-dot-xtrabars-dot-navigation-dot-accordioncontrol-6475fbff.md

latest5.4 KB
Original Source

AccordionControl.ElementClick Event

Fires when a group or item is clicked.

Namespace : DevExpress.XtraBars.Navigation

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

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

Event Data

The ElementClick event's data class is DevExpress.XtraBars.Navigation.ElementClickEventArgs.

Remarks

The ElementClick event fires when any group or item in the control is clicked. Use the Element event argument to get the clicked element. The MouseButton argument returns the clicked mouse button. The event also fires if an element is focused and the user presses the Enter or Space key.

The AccordionControlElementBase.Click event allows you to assign an event handler to a particular element. The ElementClick event fires after the Click event.

Examples

The code below shows how to prevent an item from being selected and show a pop-up form with a right-click.

csharp
using DevExpress.XtraBars.Navigation;

accordionControl1.AllowItemSelection = true;

private void accordionControl1_ElementClick(object sender, ElementClickEventArgs e) {
    if (e.MouseButton == MouseButtons.Right || e.Element.Style == ElementStyle.Group) {
        popupMenu1.ShowPopup(Control.MousePosition);
        e.Handled = true;
    }
}
vb
Imports DevExpress.XtraBars.Navigation

accordionControl1.AllowItemSelection = True

Private Sub accordionControl1_ElementClick(ByVal sender As Object, ByVal e As ElementClickEventArgs) _
    Handles accordionControl1.ElementClick
    If e.MouseButton = MouseButtons.Right OrElse e.Element.Style = ElementStyle.Group Then
        popupMenu1.ShowPopup(Control.MousePosition)
        e.Handled = True
    End If
End Sub

The code below shows how to close the pop-up form when the user clicks an item.

csharp
using DevExpress.XtraBars.Navigation;

accordionControl1.OptionsHamburgerMenu.DisplayMode = AccordionControlDisplayMode.Inline;
accordionControl1.ViewType = AccordionControlViewType.HamburgerMenu;

private void accordionControl1_ElementClick(object sender, DevExpress.XtraBars.Navigation.ElementClickEventArgs e) {
    AccordionControl accordionControl = sender as AccordionControl;
    if (e.MouseButton == MouseButtons.Left && accordionControl.IsPopupFormShown) {
        accordionControl.ClosePopupForm();
        e.Handled = true;
    }
}
vb
Imports DevExpress.XtraBars.Navigation

accordionControl1.OptionsHamburgerMenu.DisplayMode = AccordionControlDisplayMode.Inline
accordionControl1.ViewType = AccordionControlViewType.HamburgerMenu

Private Sub accordionControl1_ElementClick(ByVal sender As Object, ByVal e As ElementClickEventArgs) _
    Handles accordionControl1.ElementClick
    Dim accordionControl As AccordionControl = TryCast(sender, AccordionControl)
    If e.MouseButton = MouseButtons.Left AndAlso accordionControl.IsPopupFormShown Then
        accordionControl.ClosePopupForm()
        e.Handled = True
    End If
End Sub

The code below shows how handle the ElementClick event to prevent a particular group from being expanded with a right-click and show a pop-up menu instead. The example assumes that you placed a PopupMenu object on the component tray in the designer.

csharp
using DevExpress.XtraBars.Navigation;

private void accordionControl1_ElementClick(object sender, ElementClickEventArgs e) {
    AccordionControl accordionControl = sender as AccordionControl;
    if (e.MouseButton == MouseButtons.Right && e.Element.Style == ElementStyle.Group && e.Element == accordionControlElement1) {
        popupMenu1.ShowPopup(Control.MousePosition);
        e.Handled = true;
    }
}
vb
Imports DevExpress.XtraBars.Navigation

Private Sub accordionControl1_ElementClick(ByVal sender As Object, ByVal e As ElementClickEventArgs) _
    Handles accordionControl1.ElementClick
    Dim accordionControl As AccordionControl = TryCast(sender, AccordionControl)
    If e.MouseButton = MouseButtons.Right AndAlso e.Element.Style = ElementStyle.Group AndAlso e.Element Is accordionControlElement1 Then
        popupMenu1.ShowPopup(Control.MousePosition)
        e.Handled = True
    End If
End Sub

See Also

Click

AccordionControl Class

AccordionControl Members

DevExpress.XtraBars.Navigation Namespace