Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

AccordionControl.ElementClick Event

Fires when a group or item is clicked.

Namespace: DevExpress.XtraBars.Navigation

Assembly: DevExpress.XtraBars.v24.2.dll

NuGet Package: DevExpress.Win.Navigation

#Declaration

[DXCategory("Events")]
public event ElementClickEventHandler ElementClick

#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.

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;
    }
}

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

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;
    }
}

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.

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;
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the ElementClick event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also