// Every time the selection changes, this method is called with the // Spreadsheet as its parameter. We display the current time in the cell. private void displaySelection(SpreadsheetPanel ss) { bool succesfull = true; int newRow, newCol; //String value; // if a cell has been updated then add it to the model and //update the gui if(cellChanged) { succesfull = updateModel(row, col); } //if model was succesfully changed than make changes to the GUI if (succesfull) { //get the newly selected cell ss.GetSelection(out newCol, out newRow); displayCurrentCell(newCol, newRow); //save cells' postion row = newRow; col = newCol; } //model was not succesfull updated keep user on the incorrect cell else { spreadsheetPanel1.SetSelection(col, row); } }
// Every time the selection changes, this method is called with the // Spreadsheet as its parameter. We display the current time in the cell. private void displaySelection(SpreadsheetPanel ss) { int row, col; String value; ss.GetSelection(out col, out row); ss.GetValue(col, row, out value); if (value == "") { ss.SetValue(col, row, DateTime.Now.ToLocalTime().ToString("T")); ss.GetValue(col, row, out value); MessageBox.Show("Selection: column " + col + " row " + row + " value " + value); } }
/// <summary> /// Helper method for updating the cell's value boxes when the selection changes /// This method correctly sets the value textboxes: cellNameValue, columnValue, rowValue, cellContentsValue, and the cellValueBox textboxes /// </summary> /// <param name="sheet"></param> private void displaySelection(SpreadsheetPanel sheet) { // Create variables for holding the row, column, and cell values int row; int col; String value; // Get the current selection sheet.GetSelection(out col, out row); // Get the cell's value once the selection is obtained sheet.GetValue(col, row, out value); // Add ascii offset to the column number int asciiCol = col + 65; // Convert the ascii value into a char and set it as the columnValue text box columnValue.Text = Char.ConvertFromUtf32(asciiCol); // Add 1 to the row number since rows and columns starting index is 0 int actualRow = row + 1; // Convert row number to a string and store it in the rowValue text box rowValue.Text = actualRow.ToString(); // Combine the column and row values as a string and set them as the cellNameValue text box cellNameValue.Text = Char.ConvertFromUtf32(asciiCol) + actualRow.ToString(); // Get the contents of the cell and convert it to a string String cellContents = spreadSheet.GetCellContents(cellNameValue.Text).ToString(); // Set the cell's contents in the cellContentsValue text box cellContentsValue.Text = cellContents; // Get the vlaue of the cell and convert it to a string String cellValue = spreadSheet.GetCellValue(cellNameValue.Text).ToString(); // Set the clel's value in the cellValueBox textbox cellValueBox.Text = cellValue; }
/// <summary> /// Will populate the banner with content if it is present andhighlight the text /// so that it can be edited. If there is no content to befound then the focus is /// redirected to the content box without displaying anything. /// </summary> /// <param name="sender"></param> private void spreadsheetPanel1_SelectionChanged(SpreadsheetPanel sender) { contentBox.ResetText(); int col, row; string address; string value; string content = contentBox.Text; Send_DoneTyping(oldAddress); //Gets the currently selected cell's location and Value. spreadsheetPanel1.GetSelection(out col, out row); if (spreadsheetPanel1.GetValue(col, row, out value)) { //Assuming the cell now has a value it displays the address and corresponding value. addressBox.Text = address = gridToAddress(col, row); oldAddress = address; valueBox.Text = value; if (personalSpreadsheet.GetCellContents(address) is Formula)//Checks if the content is of type formula. { contentBox.Text = "=" + personalSpreadsheet.GetCellContents(address).ToString(); } else { contentBox.Text = personalSpreadsheet.GetCellContents(address).ToString(); } contentBox.SelectAll();//Highlights the text inside the banner. } //set oldCellAddress to this new cell address contentBox.Focus(); }
/// <summary> /// event that deels with selecting a cell, if cell already has contents it populates the approperiate labels with content information /// </summary> /// <param name="sender">spreadsheetPanel</param> private void SpreadsheetPanel1_Selection(SpreadsheetPanel sender) { //clears previous content ContentsBox.Clear(); ValueBox.Clear(); int row; int col; //used to get letter portion of cell name. char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); spreadsheetPanel1.GetSelection(out col, out row); //adds 1 to row to set name in spreadsheet cell to match panel labels. row += 1; AddressLabel.Text = "" + alpha[col] + row + ":"; //sets name for cell using row and col integers string name = "" + alpha[col] + row; string contents = sheet.GetCellContents(name).ToString(); string value = sheet.GetCellValue(name).ToString(); //checks if formula is an error if so sets cell contents to error message and error label. if (value == "SpreadsheetUtilities.FormulaError") { spreadsheetPanel1.SetValue(col, row - 1, "Formula Error"); ValueBox.Text = "Formula Error"; } //otherwise sets the value and proper content to appropreiate labels and cell. else { ValueBox.Text = value; spreadsheetPanel1.SetValue(col, row - 1, value); } //sets the contents of input box to what is in the current cell. ContentsBox.Focus(); ContentsBox.Text = contents; }
/// <summary> /// users can still click-select cells /// </summary> /// <remarks> /// This is actually trickier than it seems. We need to update the /// cell value and cell content txt boxes, update col,row, /// and ensure that focus is passed to the panel. /// Deselecting should release(write) the edit box text to the cell /// </remarks> /// <param name="sender"></param> private void Panel_SelectionChanged(SpreadsheetPanel sender) { Panel.GetSelection(out col, out row); CellNameBox.Text = this.ColRow_To_string(col, row); CellVal.Text = this.PrintableValue(sheetModel.GetCellValue(CellNameBox.Text)); string To_cell_content_box; Panel.GetValue(col, row, out To_cell_content_box); CellContents.Text = To_cell_content_box; CellContents.Select(0, CellContents.Text.Length); this.Panel.Select(); PanelFocus = true; }
/// Event handler methods below: /// <summary> /// Every time the selection changes, this method is called with the /// Spreadsheet as its parameter. /// </summary> private void DisplaySelection(SpreadsheetPanel ss) { UpdateTextBoxesAndFocus(ss); }
/// <summary> /// This method is called whenever a new cell is selected /// </summary> /// <param name="panel"></param> public void OnSelectionChanged(SpreadsheetPanel panel) { panel.GetSelection(out int col, out int row);
//A helper method to convert the currently selected cell in the panel to the currect cell name for use in Spreadsheet. private string SelectionToCell(SpreadsheetPanel panel) { int row, col; string cell; panel.GetSelection(out col, out row); cell = char.ConvertFromUtf32(col + 65) + (row + 1); return cell; }
/// <summary> /// Updates the text of given SpreadsheetPanel and focuses on enter content text box /// </summary> /// <param name="ss">A SpreadsheetPanel</param> private void UpdateTextBoxesAndFocus(SpreadsheetPanel ss) { UpdateTextBoxes(ss); CellContentTextBox.Focus(); // Focus on cell content text box }
/// <summary> /// Handles selection changed event. This selects the spreadsheetPanel element to allow navigation with arrow keys. /// </summary> /// <param name="sender"></param> private void SpreadsheetPanel_SelectionChanged(SS.SpreadsheetPanel sender) { HandleSelectionChange(); }
/// <summary> /// </summary> /// <param name="ss">The SpreadsheetPanel in the current Form1</param> private void DisplaySelection(SpreadsheetPanel ss) { if (_spreadsheet == null) return; int col, row; ss.GetSelection(out col, out row); // Convert col, row index to spreadsheet cell names. var cellName = ((char) (col + 65)) + (row + 1).ToString(CultureInfo.InvariantCulture); // Displays selected cell's name CellNameBox.Invoke(new Action(() => { CellNameBox.Text = cellName; })); var content = _spreadsheet.GetCellContents(cellName); // If content is a formula, prepend "=" before displaying var f = content as Formula; if (f != null) { ContentBox.Invoke(new Action(() => { ContentBox.Text = "=" + f; })); } // Otherwise just display the content. else { ContentBox.Invoke(new Action(() => { ContentBox.Text = content.ToString(); })); } // No need to fetch the value from the spreadsheet again, just copy it from // the spreadsheetpanel. This avoids reworking the FormulaError message. string value; ss.GetValue(col, row, out value); ValueBox.Invoke(new Action(() => { ValueBox.Text = value; })); }
/// <summary> /// Updates cells in the GUI /// </summary> /// <param name="sender"></param> private void SpreadsheetPanel1_SelectionChanged(SpreadsheetPanel sender) { //Changes the cell from numerical to variable format char coll = (char)(previousPanelCol + 97); String input = "" + coll + (previousPanelRow + 1); //Checks to see if the input is a formula if (cellInputBox.Text.IndexOf("=") == 0) { try { //Checks to see if the formula inputted is valid Formula tempForm = new Formula(cellInputBox.Text.Substring(1)); } catch (FormulaFormatException e) { //Catches and notifies users of Invalid Formulas String message = e.Message; string caption = "Formula Format Error"; var result = MessageBox.Show(message, caption, MessageBoxButtons.OK); cellInputBox.Text = ""; return; } } try { //Updates all cells that rely on this cell foreach (string cell in mainSpread.SetContentsOfCell(input, cellInputBox.Text)) { Thread temp = new Thread(() => SetCellValue(cell)); temp.Start(); } } catch (FormulaFormatException e) { //Catches and notifies users of Invalid Variables String message = e.Message; string caption = "Error: Invalid Variable"; var result = MessageBox.Show(message, caption, MessageBoxButtons.OK); cellInputBox.Text = ""; return; } catch (CircularException e) { //Catches and notifies users of Circular Dependencies String message = "The Formula Entered Creates a Circular Dependency"; string caption = "Circular Formula Error"; var result = MessageBox.Show(message, caption, MessageBoxButtons.OK); cellInputBox.Text = ""; return; } //Checks for the SUM key in order to perform operation if necessary if (cellInputBox.Text.StartsWith("SUM(") && cellInputBox.Text.EndsWith(")")) { String sum = cellInputBox.Text; sum = sum.Trim(); List <string> temp = new List <string>(Regex.Split(sum, "[(,)]")); //Removes all empty strings from temp foreach (string empty in Regex.Split(sum, "[(,)]")) { if (empty.Trim() == "") { temp.Remove(empty); } } //If there are less than two items, there wasn't anything inside the parentheses if (temp.Count < 2) { //Inform the user of the bad sum and remove it var result = MessageBox.Show("Invalid SUM: Nothing Inside Parentheses", "Invalid SUM", MessageBoxButtons.OK); cellInputBox.Text = ""; mainSpread.SetContentsOfCell(input, ""); SetCellValue(input); } else { //Trim any white space String SumStart = temp[1].Trim(); String SumEnd = temp[2].Trim(); //Make sure the given cells are actual cells if (cellValidation(SumStart) && cellValidation(SumEnd)) { //Get the character representations of the columns char col1 = SumStart.ToCharArray()[0]; char col2 = SumEnd.ToCharArray()[0]; //Pull the numeral versions of the rows from the input strings int row1 = 0; int row2 = 0; if (SumStart.Length == 3) { row1 += (SumStart.ToCharArray()[1] - 48) * 10; row1 += SumStart.ToCharArray()[2] - 49; } else { row1 += SumStart.ToCharArray()[1] - 49; } if (SumEnd.Length == 3) { row2 += (SumEnd.ToCharArray()[1] - 48) * 10; row2 += SumEnd.ToCharArray()[2] - 49; } else { row2 += SumEnd.ToCharArray()[1] - 49; } //Do the sum Summation(previousPanelCol, previousPanelRow, col1, col2, row1, row2); } //In the case of invalid cell names else { //Inform the user of the bad sum and remove it var result = MessageBox.Show("Invalid SUM: Invalid Cell Within SUM", "Invalid SUM", MessageBoxButtons.OK); cellInputBox.Text = ""; mainSpread.SetContentsOfCell(input, ""); SetCellValue(input); } } } sender.Refresh(); //Selects the box and sets up the input text form sender.GetSelection(out int col, out int row); cellInputBox.Focus(); cellInputBox.Text = GetContentsOfCell(col, row); //Shows the cell name and value at the top of the spreadsheet coll = (char)(col + 97); input = "" + coll + (row + 1); spreadsheetPanel1.GetValue(col, row, out string tempVal); CellNameLabel.Text = input.ToUpper() + " = " + tempVal; //Resets the previous value previousPanelCol = col; previousPanelRow = row; }
/// <summary> /// use to detect the spreadsheetpanel sellect change even /// if the selectded cell change, change the cellname and cell_value; /// /// </summary> /// <param name="sender"></param> private void spreadsheetPanel1_SelectionChanged(SpreadsheetPanel sender) { int col, row; spreadsheetPanel1.GetSelection(out col, out row); //parse the value to the name of cell string name = ((char)(col + 'A')).ToString() + "" + (row + 1); object value = ss.GetCellValue(name); object contents = ss.GetCellContents(name); //how to deal with formula error? cellname_textbox.Text = name; cellvalue_textbox.Text = value + ""; //judge the type of content, and set the content to relative value if (contents is double) cellcontents_textbox.Text = contents + ""; else if (contents is string) cellcontents_textbox.Text = (string)contents; else cellcontents_textbox.Text = "=" + ((Formula)contents).ToString(); }
/// <summary> /// This method is called whenever a new cell is selected /// </summary> /// <param name="panel"></param> public void OnSelectionChanged(SpreadsheetPanel panel) { panel.GetSelection(out int col, out int row); UpdateTextBoxes(GetCellName(col, row)); }
/// <summary> /// Updates the panel display, cellDisplayTextBox, contentsTextBox, valueTextBox, and all non-empty Cells /// Every time the selection changes, this method is called with the Spreadsheet as its parameter. /// </summary> /// <param name="ss"></param> private void displaySelection(SpreadsheetPanel ss) { // Get col and row of cell. int row, col; ss.GetSelection(out col, out row); string nameOfCell = "" + GetExcelColumnName(col) + (row + 1); // get cell name // Cell Display cellDisplayBox.Text = nameOfCell; // Set the valueTextBox if there is a formula error make the error message be "###########" var valueOfCell = spreadsheet.GetCellValue(nameOfCell); // get value of cell string valueOfCellString; if (valueOfCell is SpreadsheetUtilities.FormulaError) { //clientCommunication. // If it is an FormulaError we don't do anytyhing here. valueOfCellString = "##########"; } else { /**If is isn't a FormulaError, we send "CHANGE VERSION #\n" to the server. * The state of the client’s local spreadsheet should remain unchanged until approved by the server. Socket.BeginSend("message", SendCallback, null/whatever); Socket.BeginReceive(ReceiveCallback, null/whatever); probably a loop with thread.sleep in it while we wait for the message. */ valueOfCellString = valueOfCell.ToString(); } valueTextBox.Text = valueOfCellString; ss.SetValue(col, row, valueOfCellString); // update panel var contentsOfCell = spreadsheet.GetCellContents(nameOfCell); // Set the contentsTextBox, append the '=' for convience if (contentsOfCell is SpreadsheetUtilities.Formula) { contentsTextBox.Text = "=" + contentsOfCell.ToString(); } else { contentsTextBox.Text = contentsOfCell.ToString(); ss.SetSelection(col, row); } // update all non empty cells IEnumerable<string> nonEmptyCells = spreadsheet.GetNamesOfAllNonemptyCells(); foreach (var name33 in nonEmptyCells) { Match m = Regex.Match(name33, @"^([A-Z]+) *(\d)$");// separate cell name if (m.Success) { // get the column letter and convert it to a number string translated = m.Groups[1].Value; int column = TranslateColumnNameToIndex(translated); int rowNumber = Int32.Parse(m.Groups[2].Value) - 1; string valueOfDependentCellString; var valueOfDependentCell = spreadsheet.GetCellValue(name33); // Set the value if there is a formula error if (valueOfDependentCell is SpreadsheetUtilities.FormulaError) { valueOfDependentCellString = "##########"; } else { valueOfDependentCellString = valueOfDependentCell.ToString(); } ss.SetValue(column, rowNumber, valueOfDependentCellString); // update panel } } // put cursor in contents text box contentsTextBox.Focus(); contentsTextBox.Select(contentsTextBox.Text.Length, 0); }
/// <summary> /// Sets the row and column to the selected row and column. /// </summary> /// <param name="sender"></param> private void LocationHandling(SpreadsheetPanel sender) { SpreadsheetPanel panel = sender; panel.GetSelection(out rowSelected, out colSelected); string name = ((char)(rowSelected + 65)).ToString() + (colSelected + 1).ToString(); object ject = spreadsheet.GetCellContents(name); if (ject is Formula) contentsBox.Text = "=" + ject.ToString(); else contentsBox.Text = ject.ToString(); nameBox.Text = name; ject = spreadsheet.GetCellValue(name); if (ject is FormulaError) valueBox.Text = ((FormulaError)ject).Reason; else valueBox.Text = spreadsheet.GetCellValue(name).ToString(); contentsBox.Focus(); contentsBox.Select(contentsBox.Text.Length, 0); }
public DrawingPanel(SpreadsheetPanel ss) { DoubleBuffered = true; _values = new Dictionary <Address, String>(); _ssp = ss; }
/// <summary> /// Helper method that updates all text boxes when something changes /// </summary> /// <param name="s"></param> private void updateTextBox(SpreadsheetPanel s) { String name; cellValueTextBox.Focus(); //Assigns the cell name textbox to name for the selected cell name = getCellName(); cellContentsBox.Text = name; //Checks the cell if its a formula so it knows to add a '=' or not in front of the value if (ss.GetCellContents(name).GetType() == typeof(Formula)) cellValueTextBox.Text = "=" + ss.GetCellContents(name).ToString(); else { cellValueTextBox.Text = ss.GetCellContents(name).ToString(); } cellValueWindow.Text = ss.GetCellValue(name).ToString(); }
public void OnSelectionChanged(SpreadsheetPanel panel) { panel.GetSelection(out int col, out int row); panel.SetValue(col, row, GetCellName(col, row)); }
public DrawingPanel(SpreadsheetPanel ss) { DoubleBuffered = true; _values = new Dictionary<Address, String>(); _ssp = ss; }
/// <summary> /// Changes the cell name, value, and contents according to the cell you select. /// </summary> /// <param name="sender"></param> private void spreadsheetPanel1_SelectionChanged(SpreadsheetPanel sender) { //getting cell name from col and row of spreadsheetpanel int col; int row; spreadsheetPanel1.GetSelection(out col, out row); char colChar = (char)(col + 65); string cell = colChar.ToString() + (row + 1); //setting cellName text to the name of the cell cellName.Text = cell; //setting cellContents text to the contents of the selected cell. lock (ss) { object tempCellContents = ss.GetCellContents(cell); if (tempCellContents is Formula) { cellContents.Text = "=" + ((Formula)tempCellContents).ToString(); } else { cellContents.Text = tempCellContents.ToString(); } cellContents.Select(cellContents.Text.Length, 0); } //sets cellValue text after setting cell to new value. string tempValueOut; spreadsheetPanel1.GetValue(col, row, out tempValueOut); cellValue.Text = tempValueOut; }
/// <summary> /// Handler to update text boxes that give the /// information of the currently selected cell /// </summary> /// <param name="sender"></param> private void spreadsheetPanel1_SelectionChanged(SpreadsheetPanel sender) { selectedCell.Text = getSelectedCellName(); UpdateCell(); }
private void DisplayUpdate(SpreadsheetPanel ss) { if (_spreadsheet == null) return; int col, row; ss.GetSelection(out col, out row); // Convert col, row index to spreadsheet cell names. var cellName = ((char)(col + 65)) + (row + 1).ToString(CultureInfo.InvariantCulture); // Displays selected cell's name CellNameBox.Invoke(new Action(() => { CellNameBox.Text = cellName; })); // No need to fetch the value from the spreadsheet again, just copy it from // the spreadsheetpanel. This avoids reworking the FormulaError message. string value; ss.GetValue(col, row, out value); ValueBox.Invoke(new Action(() => { ValueBox.Text = value; })); }
/// <summary> /// updates the display of the GUI. /// </summary> /// <param name="ss"></param> private void update_display(SpreadsheetPanel ss) { contents_box.Select(); //stores where the user has selected on the spreadsheetpanel. int col, row; ss.GetSelection(out col, out row); //converts the col row location on the spreadsheetpanel to a usable name such as A1 for (0,0). string cell_name = (char)(65 + col) + (row + 1).ToString(); //if the contents of the highlighted cell is a double or a string this and the contents are longer than //0(meaning they aren't "" then this sets the contents box back to what the user entered before, otherwise //sets the contents box to empty. if (my_spread_sheet.GetCellContents(cell_name) is double || my_spread_sheet.GetCellContents(cell_name) is string) { if(my_spread_sheet.GetCellContents(cell_name).ToString().Length >=1) { contents_box.Text = my_spread_sheet.GetCellContents(cell_name).ToString(); } else { contents_box.Text = ""; } } //if the cell names contents are not a double or a string then it must be a formula so an = is prepended. else { contents_box.Text = "=" + my_spread_sheet.GetCellContents(cell_name).ToString(); } //if the cell name has a value then it is displayed in the value box. if (my_spread_sheet.GetCellValue(cell_name)!= null) { value_box.Text = my_spread_sheet.GetCellValue(cell_name).ToString(); } //if the cell name does not have a value then the value box is cleared. else { value_box.Clear(); } //this shows the current cell name selected along with value appended in the value label next to the value box. value_label.Text = cell_name + " Value"; contents_box.SelectAll(); }