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

adding a context menu to radpanelbargroupelement

5 Answers 81 Views
Panelbar (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
steve
Top achievements
Rank 1
steve asked on 24 Feb 2010, 12:09 AM
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);  
                }  
            }  
        } 

5 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 26 Feb 2010, 02:37 PM
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.
0
steve
Top achievements
Rank 1
answered on 02 Mar 2010, 04:31 PM
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.
0
Nikolay
Telerik team
answered on 05 Mar 2010, 02:34 PM
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.
0
steve
Top achievements
Rank 1
answered on 05 Mar 2010, 04:00 PM
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
0
steve
Top achievements
Rank 1
answered on 05 Mar 2010, 08:51 PM
Thanks, that was it. I kept using the mousedown of the RadPanelBarGroupElement instead of the RadPanelBarVisualElement. Works perfect now. 

Stephen

 

Tags
Panelbar (obsolete as of Q2 2010)
Asked by
steve
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
steve
Top achievements
Rank 1
Share this question
or