Page 1 of 1

How detect when series checkbox is selected in the legend?

Posted: Thu Sep 25, 2014 1:51 pm
by 13050364
Hi

To display the checkboxes beside each series in the legend i do this;

theChart.Legend.CheckBoxes = true;


If the user selects a checkbox how do I detect this??

Note. I need to be able to detect whether the checkbox is selected or deselected


Note. I copied this questionto the activeX thread by mistake and Ive had a reply but this does not show how to detect the status of the box.
http://www.teechart.net/support/viewtop ... =1&t=15184

Re: How detect when series checkbox is selected in the legend?

Posted: Thu Sep 25, 2014 2:14 pm
by Christopher
Hello!

You could try something like this:

Code: Select all

    private void InitializeChart()
    {
      tChart1.Aspect.View3D = false;

      for (int i = 0; i < 5; i++)
      {
        tChart1.Series.Add(typeof(Bar)).FillSampleValues();
      }

      tChart1.Legend.CheckBoxes = true;
    }


    private void button1_Click(object sender, EventArgs e)
    {
      int[] states = CheckCheckBoxStates();
      string s = "These CheckBoxes active: index(es) = ";

      for (int i = 0; i < states.Length; i++)
      {
        if (states[i] > 0)
          s += i.ToString() + " ";
      }

      MessageBox.Show(s);
    }

    private int[] CheckCheckBoxStates()
    {
      List<int> result = new List<int>();

      foreach (Series s in tChart1.Series)
      {
        result.Add(Convert.ToInt32(s.Active));
      }

      return result.ToArray();
    }

Re: How detect when series checkbox is selected in the legend?

Posted: Fri Sep 26, 2014 5:29 pm
by 13050364
Sensational! That works. Thanks Christopher