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

RadContextMenu problem

13 Answers 361 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Truong
Top achievements
Rank 1
Truong asked on 23 Apr 2012, 10:20 AM
Dear

I am trying to use RadContextMenu with RadListControl and it have one problem with current version 12.1.321.0 . When I click one context menu item the Click event occur twice. The context menu was assigned to RadListControl using RadContextMenu property.

Please have to solve this problem.

13 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 23 Apr 2012, 11:19 AM
Hello, 

When assigning a standard context menu via the ContextMenu property to a RadListControl I cannot replicate your issue. Please try this sample and let me know if this works for you

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
 
namespace RadControlsWinFormsApp1
{
    public partial class Form1 : Form
    {
 
        public Form1()
        {
            InitializeComponent();
 
            List<Item> items = new List<Item>();
            int i = 0;
            while(i <= 100)
            {
                items.Add(new Item(i, "Item " + i.ToString()));
                i++;
            }
 
            this.radListControl1.DataSource = items;
            this.radListControl1.DisplayMember = "Name";
            this.radListControl1.ValueMember = "Id";
 
            System.Windows.Forms.ContextMenu menu = new ContextMenu();
            MenuItem item1 = new MenuItem("The Menu Item");
            menu.MenuItems.Add(item1);
            item1.Click +=new EventHandler(item1_Click);
            this.radListControl1.ContextMenu = menu;
 
        }
 
        void item1_Click(object sender, EventArgs e)
        {
            RadMessageBox.Show("Clicked");
        }
 
    }
 
    public class Item
    {
        public Item()
        { }
 
        public Item(int id, string name)
        {
            Id = id;
            Name = name;
        }
 
        public int Id
        { get; set; }
 
        public string Name
        { get; set; }
 
    }
 
 
}
0
Stefan
Telerik team
answered on 23 Apr 2012, 03:22 PM
Hello Truong,

Thank you for writing.

I have tested the described behavior with RadContextMenu and RadListControl and the event was fired just once. Please refer to the attached sample. 

If you continue experiencing such a behavior, I will suggest that you open new support ticket and provide us with your project there, so we can investigate the reasons causing the undesired behavior, and provide you with adequate support.
 
Greetings,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Richard Slade
Top achievements
Rank 2
answered on 23 Apr 2012, 05:13 PM
Hi Truong, 

Just to add to that, make sure you aren't adding any event handlers in a place where they might be added multiple times. (This happened to me once) each time you would click it would add another event handler. This may be the cause of your issue
Regards, 
Richard
0
Truong
Top achievements
Rank 1
answered on 24 Apr 2012, 02:54 AM
Dear Stefan,

Thanks for your reply. I have checked your sample. It the same my program. But there is one different I used RadMenuButtonItem with RadContextMenu instead of  RadMenuItem in your sample. I use several RadContextMenu in my program all of them have the same problem.

Please check it again
0
Richard Slade
Top achievements
Rank 2
answered on 24 Apr 2012, 09:25 AM
Hello, 

With the latest version, I still cannot replicate this issue.
I have added a RadMenuButtonItem to the context menu as you have specified and it doesn't produce the behaviour you specified. 

Please can you try the following example: 

Form1 Designer File
namespace RadControlsWinFormsApp1
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
        #region Windows Form Designer generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.radListControl1 = new Telerik.WinControls.UI.RadListControl();
            this.radContextMenuManager1 = new Telerik.WinControls.UI.RadContextMenuManager();
            this.radContextMenu1 = new Telerik.WinControls.UI.RadContextMenu(this.components);
            this.radMenuItem1 = new Telerik.WinControls.UI.RadMenuItem();
            this.radMenuButtonItem1 = new Telerik.WinControls.UI.RadMenuButtonItem();
            ((System.ComponentModel.ISupportInitialize)(this.radListControl1)).BeginInit();
            this.SuspendLayout();
            //
            // radListControl1
            //
            this.radListControl1.CaseSensitiveSort = true;
            this.radListControl1.ItemHeight = 18;
            this.radListControl1.Location = new System.Drawing.Point(147, 56);
            this.radListControl1.Name = "radListControl1";
            this.radContextMenuManager1.SetRadContextMenu(this.radListControl1, this.radContextMenu1);
            this.radListControl1.Size = new System.Drawing.Size(363, 518);
            this.radListControl1.TabIndex = 0;
            this.radListControl1.Text = "radListControl1";
            //
            // radContextMenu1
            //
            this.radContextMenu1.Items.AddRange(new Telerik.WinControls.RadItem[] {
            this.radMenuItem1,
            this.radMenuButtonItem1});
            //
            // radMenuItem1
            //
            this.radMenuItem1.AccessibleDescription = "radMenuItem1";
            this.radMenuItem1.AccessibleName = "radMenuItem1";
            this.radMenuItem1.Name = "radMenuItem1";
            this.radMenuItem1.Text = "radMenuItem1";
            this.radMenuItem1.Visibility = Telerik.WinControls.ElementVisibility.Visible;
            //
            // radMenuButtonItem1
            //
            this.radMenuButtonItem1.AccessibleDescription = "radMenuButtonItem1";
            this.radMenuButtonItem1.AccessibleName = "radMenuButtonItem1";
            //
            //
            //
            this.radMenuButtonItem1.ButtonElement.AccessibleDescription = "radMenuButtonItem1";
            this.radMenuButtonItem1.ButtonElement.AccessibleName = "radMenuButtonItem1";
            this.radMenuButtonItem1.Name = "radMenuButtonItem1";
            this.radMenuButtonItem1.Text = "radMenuButtonItem1";
            this.radMenuButtonItem1.Visibility = Telerik.WinControls.ElementVisibility.Visible;
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(801, 628);
            this.Controls.Add(this.radListControl1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.radListControl1)).EndInit();
            this.ResumeLayout(false);
 
        }
 
        #endregion
 
        private Telerik.WinControls.UI.RadListControl radListControl1;
        private Telerik.WinControls.UI.RadContextMenuManager radContextMenuManager1;
        private Telerik.WinControls.UI.RadContextMenu radContextMenu1;
        private Telerik.WinControls.UI.RadMenuItem radMenuItem1;
        private Telerik.WinControls.UI.RadMenuButtonItem radMenuButtonItem1;
    }
}

Form 1 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
 
namespace RadControlsWinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
            List<Item> items = new List<Item>();
            int i = 0;
            while (i <= 100)
            {
                items.Add(new Item(i, "Item " + i.ToString()));
                i++;
            }
 
            this.radListControl1.DataSource = items;
            this.radListControl1.DisplayMember = "Name";
            this.radListControl1.ValueMember = "Id";
 
            radMenuItem1.Click += new EventHandler(item1_Click);
            radMenuButtonItem1.Click += new EventHandler(radMenuButtonItem1_Click);
        }
 
        void radMenuButtonItem1_Click(object sender, EventArgs e)
        {
            RadMessageBox.Show("Menu Button Item 1 Clicked");
        }
 
        void item1_Click(object sender, EventArgs e)
        {
            RadMessageBox.Show("Menu Item 1 Clicked");
        }
 
 
        public class Item
        {
            public Item()
            { }
 
            public Item(int id, string name)
            {
                Id = id;
                Name = name;
            }
 
            public int Id
            { get; set; }
 
            public string Name
            { get; set; }
 
        }
 
    }
}

Thanks
Richard
0
Truong
Top achievements
Rank 1
answered on 25 Apr 2012, 04:03 AM
Dear Richard,

Thanks for your sample. I have tried several times several  times but the problem still exist. I tried to convert back to Q3 2011 Sp1 and it run perfectly.
0
Richard Slade
Top achievements
Rank 2
answered on 25 Apr 2012, 09:19 AM
Hello, 

Did the sample that I gave you work however? 
I would suggest if you experience this issue again to open a support ticket and include a project that replicates the issue
Thanks
Richard
0
Stefan
Telerik team
answered on 26 Apr 2012, 03:06 PM
Hi Truong,

This will be my suggestion too. Open a ticket and provide your project there, together with the exact steps that we need to take in order to reproduce the issue. Once we are able to do so, we will be able to investigate it and provide you with adequate support.

We are looking forward to your support ticket.
 
Greetings,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Accepted
Jason
Top achievements
Rank 1
answered on 27 Apr 2012, 08:03 PM
I am having this same issue. I'm on 2012.1.12.215. The RadMenuButtonItem click event is firing twice when clicked. I removed the event handler from within the designer and it doesn't' fire at all, then readded it from the designer and it gets fired twice. The handler method itself is empty. I resolved the issue by replacing

this.m_rmbValidate.Click += new System.EventHandler( this.btnValidate_Click );
with
this.m_rmbValidate.ButtonElement.Click += new System.EventHandler( this.btnValidate_Click );

So I handle the click for the button element instead of the menu item.
0
Truong
Top achievements
Rank 1
answered on 29 Apr 2012, 05:40 AM
Dear Jason,

I have tried as your guide. It works perfectly. Thanks so much

0
Stefan
Telerik team
answered on 02 May 2012, 02:53 PM
Hello guys,

I  managed to capture the case. We were not able to do that because we were using RadMessageBox in the event handler. However, if you break in there of print something in the event handler you can see that the issue appears.

It came out that the issue is already reported by another user of ours. Feel free to add your vote for it here: http://www.telerik.com/support/pits.aspx#/details/Issue=9961.
 
Greetings,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Stefan
Telerik team
answered on 02 May 2012, 02:54 PM
Hello guys,

I managed to capture the case. We were not able to do that because we were using RadMessageBox in the event handler. However, if you break in the event handler and print something you can see that the issue appears.

It came out that the issue is already reported by another user of ours. Feel free to add your vote for it here: http://www.telerik.com/support/pits.aspx#/details/Issue=9961.
 
Greetings,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Truong
Top achievements
Rank 1
answered on 03 May 2012, 05:22 AM
Dear Stefan,

Thanks for your information. I have voted for priority of this issue.
Tags
ContextMenu
Asked by
Truong
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Stefan
Telerik team
Truong
Top achievements
Rank 1
Jason
Top achievements
Rank 1
Share this question
or