Page 1 of 1

CTools Add method

Posted: Tue Mar 10, 2009 8:18 pm
by 9532498
I'm adding 2 tools to my chart (CrossHair Cursor and Mark Tips) with the following code:

long nInt1 = m_SelectedChart->GetTools().Add(tcCursor);
long nInt2 = m_SelectedChart->GetTools().Add(tcMarksTip);

What is the long returned by the Add method? Is it the position in the list of Tools? Or is it the tooltype (tcCursor or tcMarksTip)

Later I delete these tools from the ToolsList on the chart. If I don't have any other tools present, I delete the first 2 tools in the ToolsList. But if I have other tools present, how do I know which position in the list to delete?

m_SelectedChart->GetTools().Delete(???) What is the index I use here?

Thanks.

Posted: Wed Mar 11, 2009 9:11 am
by yeray
Hi nbp,
nbp wrote:What is the long returned by the Add method? Is it the position in the list of Tools? Or is it the tooltype (tcCursor or tcMarksTip)
This method returns the index of the tool. The first will be the 0,...
nbp wrote:Later I delete these tools from the ToolsList on the chart. If I don't have any other tools present, I delete the first 2 tools in the ToolsList. But if I have other tools present, how do I know which position in the list to delete?
You could save the index of each tool when created and use it to identify the tool to delete. And the indexes should persist.

For example, the following works:

Code: Select all

int cursorIndex = axTChart1.Tools.Add(TeeChart.EToolClass.tcCursor);
int colorLineIndex = axTChart1.Tools.Add(TeeChart.EToolClass.tcColorLine);
int annotationIndex = axTChart1.Tools.Add(TeeChart.EToolClass.tcAnnotate);

axTChart1.Tools.Delete(colorLineIndex);
axTChart1.Tools.Delete(cursorIndex);
axTChart1.Tools.get_Items(annotationIndex).asAnnotation.Text = "my text";