/// <summary> /// Creates a row and is used in Create Cells /// </summary> /// <param name="rowNumber"></param> /// <returns></returns> private RowViewModel CreateRow(int rowNumber) { var row = new RowViewModel { Number = rowNumber }; return(row); }
/// <summary> /// Sets the Cell contents and updates the MainDataGrid UI /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void MainDataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { var row = (RowViewModel)e.Row.Item; // When you edit a cell this with be the row that will be updated if (e.EditAction == DataGridEditAction.Commit) { var cellName = GetCellName(e.Column, row); await SetCellContents(cellName, ((TextBox)e.EditingElement).Text); } myUpdateRow = row; myUpdateRowTimer.Change(25, Timeout.Infinite); return; }
/// <summary> /// Change the current cell in the MainDataGrid UI /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainDataGrid_CurrentCellChanged(object sender, EventArgs e) { var currentCell = MainDataGrid.CurrentCell; var column = currentCell.Column; if (column == null) { return; } var row = (RowViewModel)currentCell.Item; myCurrentColumn = column; myCurrentRow = row; myViewModel.CurrentCellName = GetCellName(column, row); return; }
/// <summary> /// initializes the MainWindow /// </summary> internal MainWindow(SpreadsheetServiceClient spreadsheetServiceClient, JoinSessionResponse joinSessionResponse) { mySpreadsheetServiceClient = spreadsheetServiceClient; spreadsheetServiceClient.CellUpdated += SpreadsheetServiceClient_CellUpdated; InitializeComponent(); myUpdateRowTimer = new Timer(UpdateRow); var viewModel = new ViewModel(this); myViewModel = viewModel; New(); // Create a new spread sheet with the data grid cleared and the name set to 'Untitled'. DataContext = viewModel; myCurrentColumn = MainDataGrid.Columns[0]; myCurrentRow = viewModel.Rows[0]; SetFocusOnCurrentCell(); Dispatcher.BeginInvoke(new Action <JoinSessionResponse>(joinSessionResponse0 => Load(joinSessionResponse0)), joinSessionResponse); }
/// <summary> /// Gets the name of a cell /// </summary> /// <param name="column"></param> /// <param name="row"></param> /// <returns></returns> private static string GetCellName(DataGridColumn column, RowViewModel row) { return((string)column.Header + row.Number.ToString(NumberFormatInfo.InvariantInfo)); }