I setup my basic chart parameters in my from load event. This works great normally but in this instance there is an issue because the form can get closed and reopened.
The chart gets it's data from another form's DGV. On the form with the DGV is a command button to open the chart form.
If the chart form is opened and closed and reopened, I get an error telling me that the series already exists....OK, makes perfect sense. I a trying to code the form load event to see if the series already exists and take action based on that. It's not working. I looked at some examples but couldn't find anything in VB, [all in C]. I thought this code would do the trick but the If Not line seems to be ignored and it blows up with "series of name1 already exists....
The chart gets it's data from another form's DGV. On the form with the DGV is a command button to open the chart form.
If the chart form is opened and closed and reopened, I get an error telling me that the series already exists....OK, makes perfect sense. I a trying to code the form load event to see if the series already exists and take action based on that. It's not working. I looked at some examples but couldn't find anything in VB, [all in C]. I thought this code would do the trick but the If Not line seems to be ignored and it blows up with "series of name1 already exists....
VB.NET:
If Not Chart1.Series.NextUniqueName = ("name1") Then
Chart1.Series.Add("name1")
Chart1.Series(0).Color = Color.Black
Chart1.Series(0).BorderWidth = 2
Chart1.Series(0).IsVisibleInLegend = True
Chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Spline
Else
Exit Sub