private void onGraphDelete(object sender, EventArgs e) { if (graphCounter <= 0) { return; } //We want to delete the graph that is on the current tab GraphPanel gp = graphTabControl.TabPages[graphTabControl.SelectedIndex].Controls[0] as GraphPanel; Graph victim = gp.Graph; app.DeleteGraph(victim); int deleteIndex = graphTabControl.SelectedIndex; graphTabControl.TabPages.Remove(graphTabControl.TabPages[deleteIndex]); graphCounter--; Console.WriteLine("Deleted " + victim.Name); if (graphCounter <= 0) { selectedItemPropertyGrid.SelectedObject = null; } }