This is a migrated thread and some comments may be shown as answers.

Creating a Manual Context Menu with RadMenuItems

1 Answer 114 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Versile
Top achievements
Rank 1
Versile asked on 05 Jun 2009, 07:53 PM
Hi,

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
                    } 
                } 
                item_counter++; 
            } 
            // Menu MA "Add" Dropdown menu 
            main_item = new Telerik.WinControls.UI.RadMenuItem("Add"); 
            ma_add_menu.Items.Add(main_item); 
            ma_all_menu.Items.Add(main_item); 
 
            // Add MA Group to "Add" menuitem 
            main_item.Items.AddRange(item); 
 
            // 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_all_menu.Items.Add(sec_item); 
             
            ma_groupbox.MouseDown += new MouseEventHandler(ma_groupbox_MouseDown); 
            ma_groupbox.Controls.AddRange(radio_btn); 
        } 
 
        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); 
            } 
        } 

1 Answer, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 08 Jun 2009, 10:35 AM
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,
Victor
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.
Tags
ContextMenu
Asked by
Versile
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or