Page 1 of 1

Removing Tools

Posted: Tue Oct 06, 2009 9:46 pm
by 15049316
Hi, I'm having problems trying to remove a Tool from the chart.Tools collection. I'm using TeeChart ActiveX and C#.

First, I add tools using this code. I keep all Toos in a Array.

Code: Select all

int index = chart.Tools.Add(EToolClass.tcColorLine);
ITools tool = mChart.Tools.get_Items(index);

// code to set tool properties

toolCollection.Add(tool); // keep for later use
Later, I want to remove a specific Tool, since I don't have its index...

Code: Select all

ITools toolToRemove = ; // here I select the tool to be removed
for (int i = 0; i < chart.Tools.Count; i++)
{
   if (chart.Tools.get_Items(i) == toolToRemove )
   {
      chart.Tools.Delete(i);
      break;
   }
}
But I can't find de saved tool object inside chart.Tools, and the tool is never removed.

Re: Removing Tools

Posted: Wed Oct 07, 2009 9:58 am
by yeray
Hi PS Soluções,

Looking into the same toolCollection it seems to work fine:

Code: Select all

        TeeChart.ITools[] toolCollection;

        private void InitializeChart()
        {
            axTeeCommander1.ChartLink = MyChart.ChartLink;

            MyChart.AddSeries(TeeChart.ESeriesClass.scLine);

            MyChart.Series(0).FillSampleValues(25);       

            toolCollection = new TeeChart.ITools[4];
            int index = MyChart.Tools.Add(TeeChart.EToolClass.tcColorLine);
            TeeChart.ITools tool = MyChart.Tools.get_Items(index);
            toolCollection[0] = tool; // keep for later use
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TeeChart.ITools toolToRemove = toolCollection[0]; // here I select the tool to be removed
            for (int i = 0; i < MyChart.Tools.Count; i++)
            {
                if (toolCollection[i] == toolToRemove)
                {
                    MyChart.Tools.Delete(i);
                    break;
                }
            }
        }

Re: Removing Tools

Posted: Wed Oct 07, 2009 1:24 pm
by 15049316
Is this code correct? I want to go into MyChart.Tools and remove a specific tool in which I have a reference (in the variable toolToRemove) but not its index.

Code: Select all

        private void button1_Click(object sender, EventArgs e)
        {
            TeeChart.ITools toolToRemove = toolCollection[0]; // here I select the tool to be removed
            for (int i = 0; i < MyChart.Tools.Count; i++)
            {
                if (toolCollection[i] == toolToRemove)
                {
                    MyChart.Tools.Delete(i);
                    break;
                }
            }
        }
What I'm trying to do is:

Code: Select all

        private void button1_Click(object sender, EventArgs e)
        {
            TeeChart.ITools toolToRemove = toolCollection[0]; // here I select the tool to be removed
            for (int i = 0; i < MyChart.Tools.Count; i++)
            {
                if (MyChart.Tools.get_Items(i) == toolToRemove)
                {
                    MyChart.Tools.Delete(i);
                    break;
                }
            }
        }

Re: Removing Tools

Posted: Tue Oct 13, 2009 11:00 am
by narcis
Hi PS Soluções,

Sorry for the delayed reply :(. I'm not sure which is your exact problem here. Is Yeray's suggestion working for you or is still not working? If not, could you please attach a simple example project we can run "as-is" to reproduce the problem here?

Thanks in advance.

Re: Removing Tools

Posted: Tue Oct 13, 2009 1:55 pm
by 15049316
Here a simple example project to show the problem I'm having.

Thanks in advance.

Re: Removing Tools

Posted: Tue Oct 13, 2009 2:13 pm
by yeray
Hi PS Soluções,

I'm not sure to see why the comparison doesn't work as expected so I'll add this to be revised in further releases.

In the meanwhile maybe we can think on a workaround but probably the easiest one would be understanding how your user is going to choose the tool to remove. Then maybe we can identify the position or the index of the tool and delete it without needing to loop into the Chart tools list.

Another workaround I can think would be having an array of integers parallel to the list of ITools and use it to store the according indexes. The problem with this solution is that every time a tool is removed, the tools with index greater than the removed tool, will change their index. That means that this array of indexes should be accordingly maintained.

Re: Removing Tools

Posted: Tue Oct 13, 2009 8:17 pm
by 15049316
Thanks for the quick reply. Both suggestions for a workaround were close to what I thought initially and I'll implement them.

Thanks again.

Re: Removing Tools

Posted: Wed Oct 14, 2009 10:47 am
by yeray
Hi PS Soluções,

I'm happy to see that you are satisfied with those suggestions but let me insist. It would be interesting for us to know how your user is going to select a tool in order to understand the sense of having another list of tools.