windowsforms-devexpress-dot-xtrabars-dot-navigation-dot-accordioncontrol-6475fbff.md
Fires when a group or item is clicked.
Namespace : DevExpress.XtraBars.Navigation
Assembly : DevExpress.XtraBars.v25.2.dll
NuGet Package : DevExpress.Win.Navigation
[DXCategory("Events")]
public event ElementClickEventHandler ElementClick
<DXCategory("Events")>
Public Event ElementClick As ElementClickEventHandler
The ElementClick event's data class is DevExpress.XtraBars.Navigation.ElementClickEventArgs.
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.
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;
}
}
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.
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;
}
}
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.
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;
}
}
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