DropDownButton

5 posts, 0 answers
  1. Najoua
    Najoua avatar
    37 posts
    Member since:
    Jun 2007

    Posted 10 Aug 2007 Link to this post

    Hi Telerik,
    I use dropdownbutton and I want that his text takes the value if the item choosed. For example, I have a drop down button with those items(All,Month...). So As a result, button.text="All" or the other item name.Is it possible?
  2. Angel
    Admin
    Angel avatar
    121 posts

    Posted 10 Aug 2007 Link to this post

    Hi Najoua,

    If the drop-down list is flat (with no hierarchy) the easiest way to do this is to use RadComboBox. If you want to have hierarchical menus in the drop-down you will have to use RadDropDownButton or RadSplitButton. In both cases you will need to write some code.

    Here is given example for RadDropDownButton.
    First subscribe for Load and FormClose events of the Form and fill them like this:

    private void Form1_Load(object sender, EventArgs e)  
    {  
        RadDropDownButtonElement buttonElement = (RadDropDownButtonElement)this.radDropDownButton1.RootElement.Children[0];  
        SubscribeMenuItems(buttonElement.DropDownMenu.Items);  
    }  
     
    private void Form1_FormClosed(object sender, FormClosedEventArgs e)  
    {  
        RadDropDownButtonElement buttonElement = (RadDropDownButtonElement)this.radDropDownButton1.RootElement.Children[0];  
        UnsubscribeMenuItems(buttonElement.DropDownMenu.Items);  

    Then add these private methods to the body of your Form class:

    private void SubscribeMenuItems(RadItemCollection menuItems)  
    {  
        for (int i = 0; i < menuItems.Count; i++)  
        {  
            RadMenuItem subMenuItem = menuItems[i] as RadMenuItem;  
            if (subMenuItem != null)  
            {  
                if (subMenuItem.Items.Count == 0)  
                    subMenuItem.Click += new EventHandler(DropDownMenuItem_Click);  
                else  
                    SubscribeMenuItems(subMenuItem.Items);  
            }  
        }  
    }  
     
    private void UnsubscribeMenuItems(RadItemCollection menuItems)  
    {  
        for (int i = 0; i < menuItems.Count; i++)  
        {  
            RadMenuItem subMenuItem = menuItems[i] as RadMenuItem;  
            if (subMenuItem != null)  
            {  
                if (subMenuItem.Items.Count == 0)  
                    subMenuItem.Click -new EventHandler(DropDownMenuItem_Click);  
                else  
                    UnsubscribeMenuItems(subMenuItem.Items);  
            }  
        }  
    }  
     
    private void DropDownMenuItem_Click(object sender, EventArgs e)  
    {  
        RadMenuItem clickedMenuItem = (RadMenuItem)sender;  
        this.radDropDownButton1.Text = clickedMenuItem.Text;  

    Hope this was helpful.
     

    Sincerely yours,
    Angel
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Najoua
    Najoua avatar
    37 posts
    Member since:
    Jun 2007

    Posted 15 Aug 2007 Link to this post

    Hi telerik,
    Thanks for your replay but I need one more support, if it is possible.
    the dropdown button I use is included in a usercontrol and not a form.So how can I define the formclosed event for usercontrol?
  5. Vassil Petev
    Admin
    Vassil Petev avatar
    1765 posts

    Posted 15 Aug 2007 Link to this post

    Najoua, this question is outside the scope of our products and we are not sure we are in the position to handle such questions. May we suggest reviewing Google and/or to trying the forums on http://windowsclient.net/? We think you will get better and more complete replies there. Thank you for your understanding.


    Best wishes,
    Rob
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Najoua
    Najoua avatar
    37 posts
    Member since:
    Jun 2007

    Posted 15 Aug 2007 Link to this post

    thanks for all.I have already find the solution to my question.
    Excuse me!
Back to Top
UI for WinForms is Visual Studio 2017 Ready