Raddropdownbutton

7 posts, 0 answers
  1. Michael
    Michael avatar
    18 posts
    Member since:
    Feb 2009

    Posted 06 Apr 2009 Link to this post

    Im using the Raddropdownbutton and populating a list of values. When the user selects a item from the dropdown list i would like to get that item selected. How can this be done? I dont see a selecteditemindex or selectvalue anyware! The list is just a flat dropdownlist.

    Please help ...and thanks in advance!
  2. John
    John avatar
    30 posts
    Member since:
    Aug 2008

    Posted 06 Apr 2009 Link to this post

    Hi Michael,
         The RadDropDownButton works a differently than a ComboBox where you select an item and the SelectionChanged event fires or you determine which index was selected.  The items for the RadDropDownButton are more like menu items where each entry will have it's own click event. 

    Hope this helps,
    John
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Michael
    Michael avatar
    18 posts
    Member since:
    Feb 2009

    Posted 06 Apr 2009 Link to this post

    Can you show me an example?
  5. John
    John avatar
    30 posts
    Member since:
    Aug 2008

    Posted 06 Apr 2009 Link to this post

    If you are adding the entry through code it would look something like this.

            private void Form1_Load(object sender, EventArgs e)  
            {  
                radDropDownButton1.Items.Clear();  
     
                //create menu item  
                var menuItem0 = new Telerik.WinControls.UI.RadMenuItem("Click me""0");  
                //add event handler  
                menuItem0.Click += new EventHandler(menuItem0_Click);  
                //add menu option to the RadDropDownButton  
                radDropDownButton1.Items.Add(menuItem0);  
            }  
     
            void menuItem0_Click(object sender, EventArgs e)  
            {  
                //perform logic for the menu item here  
                throw new NotImplementedException();  
            } 

    You can of course, add these directly in the Visual Studio designer as well. 

    John
  6. Michael
    Michael avatar
    18 posts
    Member since:
    Feb 2009

    Posted 06 Apr 2009 Link to this post

    Ok..my menu list is dynamic it changes,so how can i find the item the user selected in the menuitem list?

    Thanks again
  7. John
    John avatar
    30 posts
    Member since:
    Aug 2008

    Posted 06 Apr 2009 Link to this post

    Well, one way is to have the RadMenuItems call the same event handler and use the Tag property to identify which item was clicked.  See the example code below. 

            private void Form1_Load(object sender, EventArgs e)  
            {  
                LoadMenuOptions(5);  
            }  
     
            private void LoadMenuOptions(int numberOfItems)  
            {  
                //remove any existing event handler references  
                foreach (Telerik.WinControls.UI.RadMenuItem entry in radDropDownButton1.Items)  
                {  
                    //remove the existing event handler  
                    entry.Click -= new EventHandler(menuItems_Click);  
                }  
                radDropDownButton1.Items.Clear();  
     
                for (int i = 0; i < numberOfItems; i++)  
                {  
                    //create menu item  
                    var currentMenuItem = new Telerik.WinControls.UI.RadMenuItem("Click me" + i.ToString(), i);  
                    //add event handler  
                    currentMenuItem.Click += new EventHandler(menuItems_Click);  
                    //add menu option to the RadDropDownButton  
                    radDropDownButton1.Items.Add(currentMenuItem);  
                }  
            }  
     
            void menuItems_Click(object sender, EventArgs e)  
            {  
                if ((int)((Telerik.WinControls.UI.RadMenuItem)sender).Tag == 0)  
                {  
                    MessageBox.Show("Perform logic for option 0");  
                }  
                else if ((int)((Telerik.WinControls.UI.RadMenuItem)sender).Tag == 2)  
                {  
                    MessageBox.Show("Perform logic for option 2");  
                }  
                else 
                {  
                    MessageBox.Show("Perform logic for one of the other options");  
                }  
            } 

    So as you can see I don't have any specific reference to a hard coded entry, the tag does not have to be an integer, I just chose that for my example. 

    Hope this helps,
    John
  8. Michael
    Michael avatar
    18 posts
    Member since:
    Feb 2009

    Posted 07 Apr 2009 Link to this post

    Thanks John..that worked!!!
Back to Top
UI for WinForms is Visual Studio 2017 Ready