Profile Picture

Checkable drop down menu

Posted By Jobelle Firme 4 Years Ago
Author
Message
Jobelle Firme
Question Posted 4 Years Ago
View Quick Profile
Junior Member

Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)Junior Member (21 reputation)

Group: Forum Members
Last Active: 4 Years Ago
Posts: 8, Visits: 65
Hi. How do you create a drop down menu with checkable items but only one item can be selected? Right now I have multiple items can be checked. Thanks!


Nevron Support
Posted 4 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,000
Hi,

To have only one menu item of a drop down menu checked, you can subscribe to the MouseDown event of the menu items collection and uncheck all but the clicked menu item in the event handler.

Here's how to create a simple drop down menu:
NMenuDropDown menu = new NMenuDropDown("Menu");
menu.Items.Add(new NCheckableMenuItem("Item 1"));
menu.Items.Add(new NCheckableMenuItem("Item 2"));
menu.Items.Add(new NCheckableMenuItem("Item 3"));
menu.Items.Add(new NCheckableMenuItem("Item 4"));
menu.Items.MouseDown += OnMenuItemsMouseDown;


Here's how to uncheck all but the clicked menu item in the event handler:
private void OnMenuItemsMouseDown(NMouseButtonEventArgs arg)
{
    // Get the menu items and the clicked menu item
    NMenuItemCollection menuItems = (NMenuItemCollection)arg.CurrentTargetNode;
    NCheckableMenuItem clickedMenuItem = arg.TargetNode is NCheckableMenuItem ?
    (NCheckableMenuItem)arg.TargetNode :
    arg.TargetNode.GetFirstAncestor<NCheckableMenuItem>();

    // Uncheck all but the clicked menu item
    for (int i = 0; i < menuItems.Count; i++)
    {
        NCheckableMenuItem currentItem = menuItems[i] as NCheckableMenuItem;
        if (currentItem != clickedMenuItem)
        {
            currentItem.Checked = false;
        }
    }
}


Best Regards,
Nevron Support Team





Similar Topics


Reading This Topic