i'm building a C# winform application to display points on a chart. I'm using a combobox to select the ChartType of each Serie. When trying to put uncompatible ChartType together (point and doughnut for example), the application is crashing.
I'm trying to catch this exception with a try-catch syntax but i can't make it work.
private void Cb_curve_type_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
_chart.Series[_serie_name].ChartType = (SeriesChartType)cb_curve_type.SelectedIndex;
_chart.Update();
} catch (InvalidOperationException ex)
{
MessageBox.Show("Impossible to mix chart type", "Error", MessageBoxButtons.OK);
cb_curve_type.SelectedIndex = (int)_chart.Series[_serie_name].ChartType;
return;
}
}
I tried to remove the (InvalidOperationException ex)
to catch all exceptions but it still not working, and the program is throwing a System.InvalidOperationException on _chart.Update()
Here's the stack trace :
à System.Windows.Forms.DataVisualization.Charting.ChartTypes.PieChart.Paint(ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
à System.Windows.Forms.DataVisualization.Charting.ChartArea.Paint(ChartGraphics graph)
à System.Windows.Forms.DataVisualization.Charting.ChartPicture.Paint(Graphics graph, Boolean paintTopLevelElementOnly)
à System.Windows.Forms.DataVisualization.Charting.Chart.OnPaint(PaintEventArgs e)
à System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)
à System.Windows.Forms.Control.WmPaint(Message& m)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)