Page 1 of 1

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

Posted: Wed Aug 21, 2019 8:03 am
by 15685014
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)?

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

Posted: Wed Aug 21, 2019 2:50 pm
by Christopher
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);
        }