TeeChart for ActiveX, COM and ASP
-
PS Soluções
- Newbie
- Posts: 11
- Joined: Fri Jun 06, 2008 12:00 am
- Location: Brazil
-
Contact:
Post
by PS Soluções » Tue Oct 06, 2009 9:46 pm
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.
-
Yeray
- Site Admin
- Posts: 9614
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Wed Oct 07, 2009 9:58 am
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;
}
}
}
-
PS Soluções
- Newbie
- Posts: 11
- Joined: Fri Jun 06, 2008 12:00 am
- Location: Brazil
-
Contact:
Post
by PS Soluções » Wed Oct 07, 2009 1:24 pm
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;
}
}
}
-
Narcís
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
-
Contact:
Post
by Narcís » Tue Oct 13, 2009 11:00 am
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.
-
PS Soluções
- Newbie
- Posts: 11
- Joined: Fri Jun 06, 2008 12:00 am
- Location: Brazil
-
Contact:
Post
by PS Soluções » Tue Oct 13, 2009 1:55 pm
Here a simple example project to show the problem I'm having.
Thanks in advance.
-
Attachments
-
- TeeChartToolTest.zip
- Example project in .NET 2.0 and TeeChart Pro 8 ActiveX
- (13.06 KiB) Downloaded 554 times
-
Yeray
- Site Admin
- Posts: 9614
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Tue Oct 13, 2009 2:13 pm
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.
-
PS Soluções
- Newbie
- Posts: 11
- Joined: Fri Jun 06, 2008 12:00 am
- Location: Brazil
-
Contact:
Post
by PS Soluções » Tue Oct 13, 2009 8:17 pm
Thanks for the quick reply. Both suggestions for a workaround were close to what I thought initially and I'll implement them.
Thanks again.
-
Yeray
- Site Admin
- Posts: 9614
- Joined: Tue Dec 05, 2006 12:00 am
- Location: Girona, Catalonia
-
Contact:
Post
by Yeray » Wed Oct 14, 2009 10:47 am
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.