Profile Picture

Checkable drop down menu

Posted By Jobelle Firme Last Year
Author
Message
Jobelle Firme
Question Posted Last Year
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: Last Year
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 Last Year
View Quick Profile
Supreme Being

Supreme Being (4,088 reputation)Supreme Being (4,088 reputation)Supreme Being (4,088 reputation)Supreme Being (4,088 reputation)Supreme Being (4,088 reputation)Supreme Being (4,088 reputation)Supreme Being (4,088 reputation)Supreme Being (4,088 reputation)Supreme Being (4,088 reputation)

Group: Forum Members
Last Active: 2 Weeks Ago
Posts: 2,960, Visits: 3,353
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