RadDropDownButton prevent close?

2 posts, 1 answers
  1. David A.
    David A. avatar
    126 posts
    Member since:
    Aug 2008

    Posted 13 Feb 2012 Link to this post

    Hi,
    I have a RadDropDownButton and am using the menum items as a checklist.  The problem is I would like to keep the drop down open until the button is clicked again to allow the user to select multiple items.

    Is this possible?

    Thank you,
    David
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 16 Feb 2012 Link to this post

    Hi David,

    Thank you for writing.

    You can achieve the desired functionality by canceling the popup closing in the DropDownClosing event handler of DropDownButtonElement except when a flag raised in the MouseDown event of the DropDownButtonElement is true. Here is a sample:
    public Form1()
    {
        InitializeComponent();
     
        foreach (RadMenuItem item in radDropDownButton1.Items)
        {
            item.CheckOnClick = true;
        }
     
        radDropDownButton1.DropDownButtonElement.MouseDown += new MouseEventHandler(DropDownButtonElement_MouseDown);
        radDropDownButton1.DropDownButtonElement.DropDownClosing+=new RadPopupClosingEventHandler(DropDownButtonElement_DropDownClosing);
    }
     
    private bool preventClose = false;
     
    void DropDownButtonElement_MouseDown(object sender, MouseEventArgs e)
    {
        if (radDropDownButton1.DropDownButtonElement.IsDropDownShown)
        {
            preventClose = true;
        }
    }
     
    void DropDownButtonElement_DropDownClosing(object sender, RadPopupClosingEventArgs args)
    {
        if (preventClose)
        {
            preventClose = false;
            return;
        }
        args.Cancel = true;
    }

    I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
     
    Greetings,
    Stefan
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top