private void spreadsheetPanel1_SelectionChanged(SS.SpreadsheetPanel panel) { // Column A = 0, Row 1 = 0 thus A1 = 00 // use ascii value for columns, 65 + column value to get char then call toString // for rows, 1 + row value int row, col; panel.GetSelection(out col, out row); label1.Text = "Current Cell: " + ((char)(65 + col)).ToString() + (1 + row); label2.Text = "Cell Value: " + model.GetCellValue(getCell(col, row)).ToString(); if (model.GetCellContents(getCell(col, row)) is Formula) { string content = "=" + model.GetCellContents(getCell(col, row)).ToString(); textBox3.Text = content; } else { textBox3.Text = model.GetCellContents(getCell(col, row)).ToString(); } }
/*** Selected Cell ***/ /// <summary> /// Displays the selected cell in the non editable cell box. /// </summary> private void DisplaySelectedCell(SS.SpreadsheetPanel ss) { int row, col; // Save the users selection ss.GetSelection(out col, out row); // Get the old cell and set it's value, skipping if it's the first // selection seen so far int oldRow, oldCol; GetCellCoords(selectedCellText.Text, out oldCol, out oldRow); // oldRow and oldCol will be -1 if this is the first selection seen so far if (oldRow >= 0 && oldCol >= 0) { ss.SetSelection(oldCol, oldRow); // Check if the contents have changed, doing nothing if they haven't if (CheckForChanges(oldCol, oldRow)) ChangeCellValuebyServer(ss); // Restore the selection to the user selection ss.SetSelection(col, row); } // Display the cell name in the Cell text box string name = GetCellName(col, row); selectedCellText.Text = name; // Set the valueTextBox to the cell value valueTextBox.Text = GetValue(name); // Set the cellContents text box to the cell contents contentsTextBox.Text = GetContents(name); // Make sure focus is in the correct spot InsertMode = InsertMode; }
/************************** LOGIC CODE **************************/ /// <summary> /// Changes the cell value to it's contents. Returns true if no /// problems were encountered, false if an exception was thrown /// and caught. /// </summary> private bool ChangeCellValuebyServer(SS.SpreadsheetPanel ss) { int row, col; ss.GetSelection(out col, out row); string name = GetCellName(col, row); ISet<string> set = new HashSet<string>(); String CellCont = contentsTextBox.Text; try { CellCont = spreadsheet.NormalizeNValidate(CellCont); } catch (SpreadsheetUtilities.FormulaFormatException e) { MessageBox.Show( e.Message, "Formula Format Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } //Send the edit to the server //ENTER[esc]version_number[esc]cell_name[esc]cell_content\n client.SendMessage("ENTER" + esc + versionNumber + esc + name + esc + CellCont + "\n"); //Set the spreadsheet edited flag to true.s SSEdit = true; return true; }
/// <summary> /// Changes the cell value to it's contents. Returns true if no /// problems were encountered, false if an exception was thrown /// and caught. /// </summary> private bool ChangeCellValue(SS.SpreadsheetPanel ss) { int row, col; ss.GetSelection(out col, out row); string name = GetCellName(col, row); ISet<string> set = new HashSet<string>(); try { //Set the contents of the spreadsheet cell set = spreadsheet.SetContentsOfCell(name, contentsTextBox.Text); foreach (string s in set) { DisplayValueInTable(s); } // Display the new value in both the cell and the Value text box DisplayValueInTable(name); valueTextBox.Text = GetValue(name); } catch (SS.CircularException e) { MessageBox.Show( "ERROR: The formula you entered causes a circular dependency.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } catch (SpreadsheetUtilities.FormulaFormatException e) { MessageBox.Show( e.Message, "Formula Format Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } // Set title to have asterisk if the file is changed SetTitle(); return true; }