Creating a Manual Context Menu with RadMenuItems

2 posts, 0 answers
  1. Versile
    Versile avatar
    20 posts
    Member since:
    May 2009

    Posted 05 Jun 2009 Link to this post


    I am attempting to create a manual type of contextmenu for a radgroupbox. I add radiobuttons to the radgroup box, then 2 menu items, one is Add MA, the other is Remove MA. The Add MA should expand to the right and then down and show the selection of MA's to add. The remove would of course getElementAt and remove one of the radiobutton controls. Every attempt I have made the second menuitem never opens up. Code is below, any help would be apprecaited.

            private void setup_ma() 
                // Intialize MA object 
                ma_list = new sch_objects.MA_List(profile_list.Locationid, profile_list.Installerid); 
                ma_add_menu = new Telerik.WinControls.UI.RadDropDownMenu(); 
                ma_all_menu = new Telerik.WinControls.UI.RadDropDownMenu(); 
                // Create RadioButton grouped list in groupbox to display primary button with radio, not selectable 
                int count = ma_list.MA_list_forinstallerID.Rows.Count; 
                Telerik.WinControls.UI.RadRadioButton[] radio_btn = new Telerik.WinControls.UI.RadRadioButton[count]; 
                DataRow row; 
                Telerik.WinControls.UI.RadMenuItem main_item; 
                // Array of MA's in Installer Profile 
                for (int i = 0; i < count; i++) 
                    row = ma_list.MA_list_forinstallerID.Rows[i]; 
                    radio_btn[i] = new Telerik.WinControls.UI.RadRadioButton(); 
                    radio_btn[i].Text = row["ma"].ToString(); 
                    radio_btn[i].Name = "rb" + radio_btn[i].Text; 
                    radio_btn[i].Location = new Point(12, 21 * (i+1)); 
                    if ((bool)row["primaryma"]) 
                        radio_btn[i].ToggleState = Telerik.WinControls.Enumerations.ToggleState.On; 
                        radio_btn[i].Text = radio_btn[i].Text + " [Primary]"; 
                    // For Toggling Primary MA 
                    radio_btn[i].Click += new EventHandler(MA_Clicked); 
                    // For manually opening a right click context menu 
                    radio_btn[i].MouseDown += new MouseEventHandler(ma_radio_mousedown); 
                // Add "Add" button to group 
                Telerik.WinControls.UI.RadMenuItem[] item = new Telerik.WinControls.UI.RadMenuItem[ma_list.MA_list_forlocid.Rows.Count]; 
                int item_counter = 0
                foreach (DataRow ma_row in ma_list.MA_list_forlocid.Rows) 
                    // Create MA's for add group 
                    item[item_counter] = new Telerik.WinControls.UI.RadMenuItem(); 
                    item[item_counter].Text = ma_row["ma"].ToString(); 
                    item[item_counter].Name = "RI" + ma_row["ma"].ToString(); 
                    item[item_counter].Click += new EventHandler(add_ma_click); 
                    foreach (Telerik.WinControls.UI.RadRadioButton radio in radio_btn) 
                        if (radio.Name == ma_row["ma"].ToString()) 
                            // Delete from group if they already exist in groupbox 
                            item[item_counter].Enabled = false
                // Menu MA "Add" Dropdown menu 
                main_item = new Telerik.WinControls.UI.RadMenuItem("Add"); 
                // Add MA Group to "Add" menuitem 
                // Add "Remove MA" button to group, get MA by element location later 
                Telerik.WinControls.UI.RadMenuItem sec_item = new Telerik.WinControls.UI.RadMenuItem("Remove MA"); 
                sec_item.Click += new EventHandler(remove_ma_click); 
                ma_groupbox.MouseDown += new MouseEventHandler(ma_groupbox_MouseDown); 
            void ma_radio_mousedown(object sender, MouseEventArgs e) 
                if (e.Button == MouseButtons.Right) 
                    ma_all_menu.Show(ma_groupbox, e.Location); 
            void ma_groupbox_MouseDown(object sender, MouseEventArgs e) 
                if (e.Button == MouseButtons.Right) 
                    ma_add_menu.Show(ma_groupbox, e.Location); 

  2. Victor
    Victor avatar
    1349 posts

    Posted 08 Jun 2009 Link to this post

    Hi Versile,

    Thank you for writing. I created an application and used most of the code you provided and a few modifications. When the application runs, both menus show correctly. Please send a support ticket with a sample application which reproduces the wrong behavior. I have attached a sample application to show you what I have changed. I am looking forward to your reply.

    Best wishes,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft R3 2016 release webinar banner
Back to Top