private PointPair SafeGet(Get2ValuesForTreatment dataFunction, GrowthCurve gc)
 {
     try
     {
         return(dataFunction(gc));
     }
     catch
     {
         return(null);
     }
 }
        private void RemakeTreatmentGraphWith2(Get2ValuesForTreatment FunctionForData, String Title)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                GraphPane Graph = plotTreatments.GraphPane;
                Graph.CurveList.Clear();
                Graph.Title.Text           = Title;
                Graph.XAxis.Title.Text     = "Treatments";
                Graph.YAxis.Title.Text     = "";
                Graph.Legend.Position      = LegendPos.InsideTopLeft;
                Graph.Legend.FontSpec.Size = 8f;
                Graph.Legend.IsHStack      = true;
                SymbolType SymboltoUse = SymbolType.Circle;

                Dictionary <string, GrowthCurve> curData = GetDictionaryOfGrowthRateData();
                for (int i = 1; i < SelectablePlateMap.MAX_GROUP_ASSIGNMENTS; i++)
                {
                    Color         groupColor;
                    List <double> xVals     = new List <double>();
                    var           curNames  = selectablePlateMap1.GetNamesOfWellsAssignedToGroup(i, out groupColor);
                    string        GroupName = "";
                    if (TreatmentTextBoxes[i] != null)
                    {
                        GroupName = TreatmentTextBoxes[i].Text;
                    }
                    if (GroupName == "")
                    {
                        GroupName = "Treatment: " + i.ToString();
                    }
                    PointPairList XY = new PointPairList();
                    foreach (string name in curNames)
                    {
                        if (curData.ContainsKey(name))
                        {
                            GrowthCurve GD = curData[name];
                            PointPair   xy = SafeGet(FunctionForData, GD);
                            if (xy != null)
                            {
                                XY.Add(xy);
                            }
                        }
                    }
                    if (XY.Count > 0)
                    {
                        LineItem li = Graph.AddCurve(GroupName, XY, groupColor, SymboltoUse);
                        li.Line.IsVisible = false;
                        li.Symbol.Fill    = new Fill(groupColor);
                    }
                }
                if (chkTreatLegend.Checked)
                {
                    Graph.Legend.IsVisible = true;
                }
                else
                {
                    Graph.Legend.IsVisible = false;
                }
                Graph.XAxis.Scale.MaxGrace = .05;
                plotTreatments.AxisChange();
                plotTreatments.Invalidate();
                this.Cursor = Cursors.Default;
            }
            catch (Exception thrown)
            { MessageBox.Show("Could not make graph, talk to nigel.\n\nError is:\n" + thrown.Message, "Graph Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            finally { this.Cursor = Cursors.Default; }
        }