/// <summary> /// Handles user requests to change each /// selected cells font /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnFontClick(object sender, EventArgs e) { FontDialog fd = new FontDialog(); fd.ShowColor = true; fd.ShowEffects = true; DialogResult result = fd.ShowDialog(); if (result == DialogResult.OK) { GridPanel panel = superGridControl1.PrimaryGrid; SelectedElementCollection items = panel.GetSelectedElements(); List <GridCell> cells = items.GetCells(); foreach (GridCell cell in cells) { if (cell.IsEmptyCell == false) { cell.GridRow.Cells[cell.ColumnIndex]. CellStyles.Default.Font = fd.Font; } } } }
/// <summary> /// Handles the text update of all selected cells, when /// the user is entering txt in the toolbar textbox /// and hits the enter key. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TbxCellTextKeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; GridPanel panel = superGridControl1.PrimaryGrid; SelectedElementCollection items = panel.GetSelectedElements(); List <GridCell> cells = items.GetCells(); // See above comments about the difference in accessibility // between Empty cells and newly allocated ones. AllocateCells(cells); string s = TbxCellText.Text; foreach (GridCell cell in cells) { GridCell ncell = cell.GridRow.Cells[cell.ColumnIndex]; ncell.Value = s; ncell.GridRow.RowDirty = true; } } }
private void EraseText() { GridPanel panel = superGridControl1.PrimaryGrid; SelectedElementCollection items = panel.GetSelectedElements(); List <GridCell> cells = items.GetCells(); foreach (GridCell cell in cells) { if (cell.IsEmptyCell == false) { cell.CellStyles.Default.Font = null; cell.CellStyles.Default.TextColor = Color.Empty; cell.Value = null; } } }
/// <summary> /// Handles user requests to fill the selected cells with /// the currently set color picker background color /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CpBackgroundClick(object sender, EventArgs e) { if (CpBackground.SelectedColor.IsEmpty == false) { GridPanel panel = superGridControl1.PrimaryGrid; SelectedElementCollection items = panel.GetSelectedElements(); List <GridCell> cells = items.GetCells(); // The AllocateCells routine allocates all the cells needed // to be able to satisfy the user's request. // // Special care should be taken to understand that the List of cells // returned in the call to items.GetCells is only useful for the // determination of row and column details, and is not valid for any // type of modification. // // After cell allocation has taken place, the grid rows now contain // newly created cells - and it is those cells that need to be referenced // in any future cell operation. AllocateCells(cells); Background background = new Background(CpBackground.SelectedColor); foreach (GridCell cell in cells) { // Make sure we use any newly allocated cell, and not // a potentially Empty cell retrieved in the selection list GridCell ncell = cell.GridRow.Cells[cell.ColumnIndex]; ncell.CellStyles.Default.Background = background; } // Clear all user selections so that the // background change is more apparent to the user. panel.ClearAll(); } }
/// <summary> /// Handles grid selection changes by updating the /// toolbar textbox if all selected cells have the /// same content value. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void SuperGridControl1SelectionChanged(object sender, GridEventArgs e) { GridPanel panel = superGridControl1.PrimaryGrid; SelectedElementCollection items = panel.GetSelectedElements(); List <GridCell> cells = items.GetCells(); string s = null; if (cells.Count > 0) { foreach (GridCell cell in cells) { if (ValuesMatch(ref s, (string)cell.Value) == false) { break; } } } TbxCellText.Text = s ?? ""; }