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

Context Menu Closing problem

6 Answers 816 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Braden
Top achievements
Rank 1
Braden asked on 14 Aug 2018, 03:58 PM

Hello all,

My problem is this: I have a drop down list inside of a context menu. When the selected index changes, I want to open that specific page view (handled by GoToWindow() method) and close the drop down and the parent context menu. 

However, I can't figure out a way to have the context menu know when I am clicking on something in the child DropDownList element.

Here's my code for the context menu opening: 

private void MPLList_GridView_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
        {
 
            List<BPPriceMstr> myBP = new List<BPPriceMstr>();
            FactoryOrder bpOrder = new FactoryOrder();
            int index = MPLList_GridView.Rows.IndexOf(MPLList_GridView.CurrentRow);
            bpOrder.AddOrderLine("CardCode", masterPriceLists[index].Business.CardCode);
 
            BPPriceMstrFactory bpFactory = new BPPriceMstrFactory();
            tmpDDL_MPLLists = bpFactory.BuildPriceMstr(bpOrder);
 
            
            /////////////////////////////
            //new code -- RRM and BRA
            /////////////////////////////
 
            //create empty drop down list
 
            RadDropDownList mplDropDownList = new RadDropDownList();
            mplDropDownList.Text = "Select MPL";
 
            //iterate over all MPLs and add them to the drop down list
            foreach (BPPriceMstr mpl in tmpDDL_MPLLists)
            {
                mplDropDownList.Items.Add(new RadListDataItem(mpl.StartDate.ToShortDateString() + " - " + mpl.EndDate.ToShortDateString()));
            }
 
            //add selected index changed event handler
            mplDropDownList.SelectedIndexChanged += mplDropDownList_SelectedIndexChanged;
 
            //create content item for drop down list
            RadMenuContentItem contentItem = new RadMenuContentItem();
            RadHostItem host = new RadHostItem(mplDropDownList);
 
            //populate the drop down list
            contentItem.ContentElement = host;
 
            //set the size of the MPL drop down menu
            contentItem.AutoSize = false;
            contentItem.Size = new System.Drawing.Size(150, 100);
 
            //here we add an arrow to select MPL from the drop down list.
            //if only one MPL, there will be only one to choose from
 
            RadMenuItem mplSpecific = new RadMenuItem();
            mplSpecific.Text = "Open Specific Master Price List";
            mplSpecific.Items.Add(contentItem);
            RadMenuSeparatorItem separator = new RadMenuSeparatorItem();
            e.ContextMenu.Items.Add(separator);
            e.ContextMenu.Items.Add(mplSpecific);
 
 
        }

 

Then, here is my method for when the selected index is changed for the drop down:

private void mplDropDownList_SelectedIndexChanged (object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            //this method gets called whenever the DDL index is changed
            //i.e. whenever a user selects a different MPL date range
            RadDropDownList list = sender as RadDropDownList;
 
            if(list != null && e.Position > -1)
            {
                //Console.WriteLine("New Selected Item: " + list.Items[e.Position]);
                //get the mpl id for the MPL date range selected
                int mplid = tmpDDL_MPLLists[e.Position].Id;
                FactoryOrder myOrder = new FactoryOrder();
                //create an order tuple to open the specific MPL page we want to view
                myOrder.AddOrderLine("SpecificList", mplid.ToString());
 
                //jump manager to pull up a specific MPL window tab
                JumpOrder myJumpOrder = new JumpOrder();
                myJumpOrder.factoryOrder = myOrder;
                myJumpOrder.module = "MPL";
                myJumpOrder.targetWin = "MPLS";
 
                //issue: new MPLS tab should have date range populated
 
                MainDockWin.mainJumpManager.PassJumpOrder(myJumpOrder);
                MainDockWin.mainJumpManager.GoToWindow();
            }
            //need a way to hide the parent menu when sub-menu item is clicked and we jump...
            //list.Visible = false;
 
            //this only hides the MPL drop down list...
            //how to hide the context menu?
            //list.Parent.Visible = false;
 
            //let the context menu know that there was a click...and close
 
            list.Parent.Hide();
             
        }

 

The list.Parent.Hide (or set Visible=false) only hides the drop down menu, not the overall context menu. list.Parent.Parent returns null. Any and all help is appreciated! Thanks

See attached screenshot for what I'm referring to as the behavior of my program.

6 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Aug 2018, 12:12 PM
Hello, Braden,      

In the RadGridView.ContextMenuOpening event you have access to the main menu of RadGridView. You can store it into a variable and when a new item is selected in the hosted RadDropDownList you can simply use the Hide method of the stored menu:
public RadForm1()
{
    InitializeComponent();
 
    this.radGridView1.ContextMenuOpening += radGridView1_ContextMenuOpening;
}
 
RadDropDownMenu contextMenu;
private void radGridView1_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
{
    contextMenu = e.ContextMenu;
   // some other code
}
 
private void mplDropDownList_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
    contextMenu.Hide();
}

I hope this information helps. If you have any additional questions, please let me know.  
 
Regards,
Dess
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Braden
Top achievements
Rank 1
answered on 15 Aug 2018, 01:16 PM
Works perfectly - thank you! Is there any specific section of the docs to look in the future so I don't need to make a forum post every time? Haha. Like I said, I'm still new to Winforms (and Telerik UI), and C# so it's taking me a bit. Thank you again for your help.
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Aug 2018, 01:45 PM
Hello, Braden,      

You can refer to the following section in the online documentation which gives you some additional information about the context menu in RadGridView: https://docs.telerik.com/devtools/winforms/gridview/context-menus/custom-context-menus

Note that we strive to constantly improve our documentation, however, it is not possible to cover all scenarios and it is absolutely normal that any questions arise during the development process. That is why I would recommend you to download a 30-day free trial and explore the toolkit and consider using it for your current or upcoming WinForms development. It comes with 30 days free support package and you are free to submit tickets for any assistance that you need with the Telerik UI for WinForms suite.  

Note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.

I hope this information helps.

Regards,
Dess
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alien
Top achievements
Rank 1
answered on 22 Dec 2019, 04:37 PM
I'm on R2 2019 version and I'm really confused why it doesn't have hide. how am i suppose to hide it by code 
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Dec 2019, 12:47 PM

Hello, Alien,     

RadContextMenu and RadDropDownMenu (used in RadGridView) are two different types of menu. Hence, they provide different API as well. 

RadContextMenu offers DropDown property which is of type RadDropDownMenu. So you can use the RadContextMenu.DropDown.Hide method.
    this.radContextMenu1.DropDown.Hide();
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Alien
Top achievements
Rank 1
answered on 26 Dec 2019, 10:31 PM
thank you
Tags
ContextMenu
Asked by
Braden
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Braden
Top achievements
Rank 1
Alien
Top achievements
Rank 1
Share this question
or