changeset 50:c972fb283675

Fixes #149: Crash with edit on null tree item * Clean up code - can't seem to recreate
author IBBoard <dev@ibboard.co.uk>
date Tue, 15 Sep 2009 19:41:41 +0000
parents 93b3d23147ba
children 53a18feb2370
files FrmArmyTree.cs
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/FrmArmyTree.cs	Mon Sep 14 20:43:52 2009 +0000
     1.2 +++ b/FrmArmyTree.cs	Tue Sep 15 19:41:41 2009 +0000
     1.3 @@ -314,19 +314,21 @@
     1.4  		private void EditUnit()
     1.5  		{
     1.6  			TreeNode selected = treeView.SelectedNode;
     1.7 +			object tagData = selected.Tag;
     1.8  
     1.9 -			if (selected.Tag!=null && selected.Tag is Unit)
    1.10 +			if (tagData is Unit)
    1.11  			{
    1.12 -				Unit unit = (Unit)selected.Tag;
    1.13 +				Unit unit = (Unit) tagData;
    1.14 +				string unitID = unit.ID;
    1.15  
    1.16 -				if (unitWindows.ContainsKey(unit.ID))
    1.17 +				if (unitWindows.ContainsKey(unitID))
    1.18  				{
    1.19 -					unitWindows[unit.ID].Focus();
    1.20 +					unitWindows[unitID].Focus();
    1.21  				}
    1.22  				else
    1.23  				{
    1.24  					FrmUnit unitForm = new FrmUnit(unit, commandStack);
    1.25 -					unitWindows.Add(unit.ID, unitForm);
    1.26 +					unitWindows.Add(unitID, unitForm);
    1.27  					unitForm.MdiParent = this.MdiParent;
    1.28  					unitForm.Closing+=new CancelEventHandler(unitForm_Closing);
    1.29  					unitForm.Show();