adding a context menu to radpanelbargroupelement

6 posts, 0 answers
  1. steve
    steve avatar
    81 posts
    Member since:
    Oct 2009

    Posted 23 Feb 2010 Link to this post

    I need dynamically add a context menu to radpanelbargroupelement.

    the radpanelbargroupelement are created dynamically and I need to have it when you right click the groupelement the menu display and excepts only on the right click for that groupelement.  here is what I have but it is not fireing the event when right clicked.


     private void PopulatePanelBar()  
            {  
                RadPanelBarGroupElement ItemsGroupElement;  
                foreach (BEItems.ItemRow gcr in ItemsDataSet.Item.Rows)  
                {  
                    ItemsGroupElement = new RadPanelBarGroupElement();  
                    ItemsRadPanelBar.Items.Add(ItemsGroupElement);  
     
                    ItemsGroupElement.Caption = gcr.Item_nm;  
                    ItemsGroupElement.Tag = gcr.Item_id;  
                    ItemsGroupElement.MouseDown += new MouseEventHandler(ItemsGroupElement_MouseDown);  
                }  
                foreach (RadPanelBarGroupElement element in this.ItemsRadPanelBar.Items)  
                {  
                    RadPanelBarVisualElement visualElement = element.GetCaptionElement();  
                    element.EnableHostControlMode = true;  
                    visualElement.AutoToolTip = true;  
     
                    ItemUserControl ItemUserControl = new ItemUserControl();  
                    element.ContentPanel.Controls.Add(ItemUserControl);  
                    ItemUserControl.ItemHeaderRow = (BEItems.Item_headerRow[])ItemsDataSet.Item_header.Select("Item_id = " + (int)element.Tag);  
                    ItemUserControl.ItemValueRow = (BEItems.Item_valueRow[])ItemsDataSet.Item_value.Select("Item_id = " + (int)element.Tag);  
                }  
            }  
            void ItemsGroupElement_MouseDown(object sender, MouseEventArgs e)  
            {  
                if (e.Button == MouseButtons.Right)  
                {  
                    ContextMenu myMenu = new ContextMenu();  
                    if (sender != null)  
                    {  
                        RadPanelBarGroupElement element = (RadPanelBarGroupElement)sender;  
                        element.ContentPanel.ContextMenu = myMenu;  
     
                        MenuItem AddItemRadMenuItem = new MenuItem();  
                        MenuItem UpdateItemRadMenuItem = new MenuItem();  
                        MenuItem InactivateItemRadMenuItem = new MenuItem();  
                        MenuItem ExpandPanelBarRadMenuItem = new MenuItem();  
                        MenuItem CollapsePanelBarRadMenuItem = new MenuItem();  
     
                        AddItemRadMenuItem.Click += new EventHandler(AddItemRadMenuItem_Click);  
                        UpdateItemRadMenuItem.Click += new EventHandler(UpdateRadMenuItem_Click);  
                        InactivateItemRadMenuItem.Click += new EventHandler(InactivateItemRadMenuItem_Click);  
                        ExpandPanelBarRadMenuItem.Click += new EventHandler(ExpandPanelBarRadMenuItem_Click);  
                        CollapsePanelBarRadMenuItem.Click += new EventHandler(CollapsePanelBarRadMenuItem_Click);  
     
                        myMenu.MenuItems.Add(AddItemRadMenuItem);  
                        myMenu.MenuItems.Add(UpdateItemRadMenuItem);  
                        myMenu.MenuItems.Add(InactivateItemRadMenuItem);  
                        myMenu.MenuItems.Add(ExpandPanelBarRadMenuItem);  
                        myMenu.MenuItems.Add(CollapsePanelBarRadMenuItem);  
                    }  
                }  
            } 
  2. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 26 Feb 2010 Link to this post

    Hi steve,

    If I have understood your case correctly, you want to show a ContextMenu when you are in the ConentPanel of a group. In this case you need to subscribe to the MouseDown event of the ContentPanel. Please refer to the following snippet for additional information:
    private void PopulatePanelBar()
    {
        RadPanelBarGroupElement ItemsGroupElement;
        for (int i = 0; i < 5; i++)
        {
            ItemsGroupElement = new RadPanelBarGroupElement();
            this.radPanelBar1.Items.Add(ItemsGroupElement);
            ItemsGroupElement.Caption = "Name" + i.ToString();
            ItemsGroupElement.Tag = i;
            ItemsGroupElement.ContentPanel.Tag = ItemsGroupElement;
            ItemsGroupElement.ContentPanel.MouseDown += new MouseEventHandler(ContentPanel_MouseDown);
        }
      
        foreach (RadPanelBarGroupElement element in this.radPanelBar1.Items)
        {
            RadPanelBarVisualElement visualElement = element.GetCaptionElement();
            element.EnableHostControlMode = true;
            visualElement.AutoToolTip = true;
        }
    }
      
    void ContentPanel_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {
            ContextMenu myMenu = new ContextMenu();
            if (sender != null)
            {
                RadTabStripContentPanel panel = (RadTabStripContentPanel)sender;
                panel.ContextMenu = myMenu;
      
                MenuItem AddItemRadMenuItem = new MenuItem();
                AddItemRadMenuItem.Text = ((RadPanelBarGroupElement)panel.Tag).Caption;
                MenuItem UpdateItemRadMenuItem = new MenuItem();
                MenuItem InactivateItemRadMenuItem = new MenuItem();
                MenuItem ExpandPanelBarRadMenuItem = new MenuItem();
                MenuItem CollapsePanelBarRadMenuItem = new MenuItem();
      
                myMenu.MenuItems.Add(AddItemRadMenuItem);
                myMenu.MenuItems.Add(UpdateItemRadMenuItem);
                myMenu.MenuItems.Add(InactivateItemRadMenuItem);
                myMenu.MenuItems.Add(ExpandPanelBarRadMenuItem);
                myMenu.MenuItems.Add(CollapsePanelBarRadMenuItem);
            }
        }
    }

    I hope this helps. If you have additional questions, feel free to contact me.

    Greetings,
    Nikolay
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. steve
    steve avatar
    81 posts
    Member since:
    Oct 2009

    Posted 02 Mar 2010 Link to this post

    Sorry, no I want to be able to right click the radPanelBarGroupElement and have a context menu apear.  It works fine if I do not create a dynamic groupelement, but when the groupelement is dynamic, right click does not work.  Left works just fine but not right click.  Putting the mousedown event does not fire the right click in either place (content or group element).

    Thanks.
  5. Nikolay
    Admin
    Nikolay avatar
    1804 posts

    Posted 05 Mar 2010 Link to this post

    Hello steve,

    If you want to show a context menu for the caption (RadPanelBarVisualElement) of the RadPanelGroupElement, you should subscribe to its MouseDown as well. I am attaching a sample project which demonstrates the approach. If you still have difficulties in implementing your scenario, please open a new support ticket and send me a sample project which demonstrates them. This will allow me to provide you with a more accurate response.

    Sincerely yours,
    Nikolay
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. steve
    steve avatar
    81 posts
    Member since:
    Oct 2009

    Posted 05 Mar 2010 Link to this post

    OK, I will look at the prject and if it doesn't work or help point me in the right direction, I will add it to the other project I am submitting later this after noon regarding adding controls and resining to fit that control to the panel bar. 

    Thanks
  7. steve
    steve avatar
    81 posts
    Member since:
    Oct 2009

    Posted 05 Mar 2010 Link to this post

    Thanks, that was it. I kept using the mousedown of the RadPanelBarGroupElement instead of the RadPanelBarVisualElement. Works perfect now. 

    Stephen

     

Back to Top
UI for WinForms is Visual Studio 2017 Ready