//call on cell changes
		public void CellChanged(CellKey key)
		{
            bool breakAll = false;
			foreach (System.Windows.Forms.Control c in mainForm.WorksheetsTabControl.SelectedTab.Controls)
			{
				if (c is SpreadsheetUserControl)
				{
					SpreadsheetUserControl ActiveWS = (SpreadsheetUserControl)c;
                    int times = 0;
                    CellKey lastUpdated = null;
					string val = null;
					InvalidateCell(key);
					while (InvalidCells.Count > 0)
					{
						key = InvalidCells.Dequeue();

                        times++;
                        if (times > 400)
                        {
                            breakAll = true;
                            break;//Circular Reference
                        }

                        if (lastUpdated != null)
                            if (lastUpdated.Equals(key))
						    {
                                breakAll = true;
                                break;//Self Reference
						    }

						//val == null or value in new cell
						//val = parse(key, m.Cells[key].Value);
						if (val != null)
						{
							UpdateCellValue(key, val);
							lastUpdated = key;
						}
						val = Controller.Instance.Parser.Parse(ActiveWS, SpreadsheetView.MakeColumnLabel(key.C) + key.R + ":" + ActiveWS.Spreadsheet.SpreadsheetModel.Cells[key].Formula);
						UpdateCellValue(key, val);
						//updateCellValue(key, parse(key, m.Cells[key].value)); call the parse function for this cell key
					}
                    if (breakAll == true) break;
				}
			}
		}
        //call on cell changes
        public void CellChanged(CellKey key)
        {
            CellKey lastUpdated = null;
            string val = null;
            InvalidateCell(key);
            while (InvalidCells.Count > 0)
            {
                key = InvalidCells.Dequeue();

                if (lastUpdated == key)
                {
                    //circular Reference
                }
                //val == null or value in new cell
                //val = parse(key, m.Cells[key].Value);
                if (val != null)
                {
                    UpdateCellValue(key, val);
                    lastUpdated = key;
                }
                //updateCellValue(key, parse(key, m.Cells[key].value)); call the parse function for this cell key
            }
        }
        public Cell this[CellKey key]
        {
            get 
            {
                if(cells.ContainsKey(key))
                    return cells[key];

                return null;
            }
            set
            {
                if (cells.ContainsKey(key))
                    cells[key] = value;
                else
                {
                    cells.Add(key, value);
                    if (key.C >= cols)
                        cols = key.C + 1;
                    if (key.R >= rows)
                        rows = key.R + 1;
                }
            }
        }
 public void ClearCell(CellKey key)
 {
     m.Cells[key].Formula = null;
     m.Cells[key].Value = "";
     //repaint
 }
 public void UpdateCellFormula(CellKey key, string formula)
 {
     m.Cells[key].Formula = formula;
     //repaint
 }
 public void UpdateCellValue(CellKey key, string value)
 {
     m.Cells[key].Value = value;
 }
 //enqueue invalid cell
 public void InvalidateCell(CellKey key)
 {
     InvalidCells.Enqueue(key);
 }
		public void ClearCell(CellKey key)
		{
			foreach (System.Windows.Forms.Control c in mainForm.WorksheetsTabControl.SelectedTab.Controls)
			{
				if (c is SpreadsheetUserControl)
				{
					SpreadsheetUserControl ActiveWS = (SpreadsheetUserControl)c;
					ActiveWS.Spreadsheet.SpreadsheetModel.Cells[key].Formula = null;
					ActiveWS.Spreadsheet.SpreadsheetModel.Cells[key].Value = "";
					//repaint
				}
			}
		}
		public void UpdateCellFormula(CellKey key, string formula)
		{
			foreach (System.Windows.Forms.Control c in mainForm.WorksheetsTabControl.SelectedTab.Controls)
			{
				if (c is SpreadsheetUserControl)
				{
					SpreadsheetUserControl ActiveWS = (SpreadsheetUserControl)c;
					ActiveWS.Spreadsheet.SpreadsheetModel.Cells[key].Formula = formula;
					ActiveWS.Spreadsheet.RefreshCell(key);
				}
			}
		}
 ICell ICellCollection.this[CellKey key] { get { return this[key]; } }
 public void RefreshCell(CellKey key)
 {
     //if null, we dont care!
     try
     {
         if (spreadsheetModel.Cells[key] != null)
         {
             this[key.C, key.R].Value = spreadsheetModel.Cells[key].Value;
             this[key.C, key.R].Style.Font = spreadsheetModel.Cells[key].CellFormat.CellFont;
             this[key.C, key.R].Style.ForeColor = spreadsheetModel.Cells[key].CellFormat.TextColor;
             this[key.C, key.R].Style.BackColor = spreadsheetModel.Cells[key].CellFormat.CellColor;
             Controller.Instance.MainForm.FontSizeSelectionBox.SelectedIndex = (int)spreadsheetModel.Cells[key].CellFormat.CellFont.Size;
             this.Columns[key.C].Width = spreadsheetModel.Cells[key].CellFormat.CellWidth;
             this.Rows[key.R].Height = spreadsheetModel.Cells[key].CellFormat.CellHeight;
         }
         else
             this[key.C, key.R].Value = null;
     }
     catch (NullReferenceException e)
     {
     }
 }