I'm adding DrawLineItems to the Lines collection and that's fine --
Until the chart tries to refresh and throws an exception because all the "Handles" fields such as EndHandle, MidlleBottomHandle, MiddleTopHandle, and Starthandle are Null so a NullReferenceException is thrown.
My question is how to either populate the Handle values or avoid the exception when programmatically adding DrawLineItems to a .Net TeeChart?
Error
My populate code:
Null "Handle's" in DrawLineItems
Also when I add the line to the DrawLines Lines collection it doesn't throw the newline event like when I draw the line on the screen by hand with the mouse.
Thanks for your help.
Joseph
Programmatically Creating DrawLineItem Error Null Handles Exception
-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Programmatically Creating DrawLineItem Error Null Handles Exception
Hello Joseph,
I think the reason is that you are using the parameterless constructor of DrawLineItem, which means that EndHandle will throw an error (following code is from the sourcecode):
It will throw an error because the tool variable is null - this is the parameter you can pass in the other constructor of DrawLineItem, e.g.
I think the reason is that you are using the parameterless constructor of DrawLineItem, which means that EndHandle will throw an error (following code is from the sourcecode):
Code: Select all
public Rectangle EndHandle
{
get
{
return RectangleFromPoint(tool.AxisPoint(EndPos));
}
}
Code: Select all
private void InitializeChart(TChart chart)
{
chart.Series.Add(typeof(Line)).FillSampleValues();
var drawLine = new DrawLine(chart.Chart);
var item = new DrawLineItem(drawLine); //<-- pass in the 'tool' here
item.Pen.Width = 3;
item.Pen.Color = Color.Red;
item.StartPos = new PointDouble(1, 1);
item.EndPos = new PointDouble(3, chart.Series[0].YValues.Maximum);
drawLine.Lines.Add(item);
}
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Programmatically Creating DrawLineItem Error Null Handles Exception
Christopher - u r correct! I feel dumb for missing the constructor that takes the drawline object as a param.
Thanks soooooo much!!!-
- Guru
- Posts: 1603
- Joined: Fri Nov 15, 2002 12:00 am
Re: Programmatically Creating DrawLineItem Error Null Handles Exception
Hello Joseph!
You are very welcome! Don't forget that debugging such issues is considerably easier with the source code
Best Regards,
Christopher Ireland / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |