How to cast Steema.TeeChart.Chart class to Steema.TeeChart.TChart class

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
bairog
Advanced
Posts: 128
Joined: Fri Dec 07, 2018 12:00 am

How to cast Steema.TeeChart.Chart class to Steema.TeeChart.TChart class

Post by bairog » Wed Aug 21, 2019 8:03 am

I have several charts (instances of Steema.TeeChart.TChart class) on my form (let's say tChart1, tChart2, etc.).
I have TChart_ClickSeries(object sender, Series s, int valueIndex, MouseEventArgs e) method which I want to use for all charts.
And in this method I need to check for what chart exactly is is being called:

Code: Select all

if (sender.Equals(tChart1))
{ ... }
else
{ ... }
But the sender is Steema.TeeChart.Chart class, not Steema.TeeChart.TChart - so if statement is not working. Steema.TeeChart.Chart class has no Name property - so I cannot check by name.
How to cast Steema.TeeChart.Chart class to Steema.TeeChart.TChart class (or compare it with Steema.TeeChart.TChart)?

Christopher
Guru
Posts: 1603
Joined: Fri Nov 15, 2002 12:00 am

Re: How to cast Steema.TeeChart.Chart class to Steema.TeeChart.TChart class

Post by Christopher » Wed Aug 21, 2019 2:50 pm

You could try using the Parent property, i.e.

Code: Select all

        private void TChart1_ClickSeries(object sender, Series s, int valueIndex, MouseEventArgs e)
        {
            var tchart = sender as Chart;
            var parent = tchart.Parent;
            MessageBox.Show(parent.GetControl().Name);
        }
Best Regards,
Christopher Ireland / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Instructions - How to post in this forum

Post Reply