Page 1 of 1

Context menu for Chart Editor object

Posted: Tue Mar 02, 2010 8:21 am
by 15655322
Hi,
I've tried to implement a ContextMenuStrip for the Chart Editor, but it doesn't get enabled (strip is not displayed when right-click).
I've used the same-alike implementation (standard .net) I've done for the Chart object in another module of the application, where it works.
Thanks for any hints! The code follows:

Code: Select all

editChart = new TChart();
editor1 = new Steema.TeeChart.Editors.ChartEditor(editChart.Chart);
// .......
ToolStripMenuItem stripAfficheCharte = new ToolStripMenuItem("Action here");
contextMenu = new ContextMenuStrip();
contextMenu.Items.AddRange(new ToolStripItem[] { stripAfficheCharte });
stripAfficheCharte.Click += new System.EventHandler(stripAfficheCharte_Click);
editor1.ContextMenuStrip = contextMenu;

Re: Context menu for Chart Editor object

Posted: Thu Mar 04, 2010 8:32 am
by yeray
Hi Gabriel,

Could you please tell us what exact TeeChart and Visual Studio version are you using? Here your code seems to works as expected:

Code: Select all

        private void button1_Click(object sender, EventArgs e)
        {
            Steema.TeeChart.TChart editChart = new Steema.TeeChart.TChart();
            Steema.TeeChart.Editors.ChartEditor editor1 = new Steema.TeeChart.Editors.ChartEditor(editChart.Chart);
            // .......
            ToolStripMenuItem stripAfficheCharte = new ToolStripMenuItem("Action here");
            ContextMenuStrip contextMenu = new ContextMenuStrip();
            contextMenu.Items.AddRange(new ToolStripItem[] { stripAfficheCharte });
            stripAfficheCharte.Click += new System.EventHandler(stripAfficheCharte_Click);
            editor1.ContextMenuStrip = contextMenu;
            editor1.Show();
        }

        void stripAfficheCharte_Click(object sender, EventArgs e)
        {
            MessageBox.Show("hello");
        }

Re: Context menu for Chart Editor object

Posted: Thu Mar 04, 2010 10:10 am
by 15655322
Hi thanks, but it doesn't work as is (did u really try it?).
I've found the solution though: the context menu statements need to be executed during the editor1.Load event. And it works fine this way.
For info, I'm using your latest TeeChart release (just bought it) and VS 2008 and 2010 RC.

Re: Context menu for Chart Editor object

Posted: Thu Mar 04, 2010 10:38 am
by yeray
Hi Gabriel,

Yes I tied it. Here is the result I obtain in a new WinForms application. Simply adding a button, the teechart reference and the code above.
(Here I use Windows 7 x86, VS2008, TeeChart NET v4.0.2009.62332.)
contextmenu.png
contextmenu.png (99.05 KiB) Viewed 4540 times
Anyway, I'm glad to see that you've found a solution for it.

Re: Context menu for Chart Editor object

Posted: Thu Mar 04, 2010 10:50 am
by 15655322
Sorry if my comment seemed to be offensive, but just wanted to get into .net guts :wink: . In fact is not a Tchart issue here, but .net.
Combining our solutions, it converges to the fact that the context menu construction should be fired inside an event: the button for you, the load page in my case.
Cheers