// invalidate grid after adding new rows // (so the Added style is visible right away) private void _drChanged(object sender, DataRowChangeEventArgs e) { if (e.Action == DataRowAction.Add) { _flex.Invalidate(); } }
private void _flex1_CellChanged(object sender, C1.Win.C1FlexGrid.RowColEventArgs e) { // invalidate row to force repaint if (_flex1.Cols[e.Col].Name == "UserDef") { _flex1.Invalidate(e.Row, -1); } }
private void _flex_AfterSelChange(object sender, C1.Win.C1FlexGrid.RangeEventArgs e) { // invalidate whole rows between old and new ranges // (more efficient than simply calling Invalidate()) int r1 = Math.Min(e.OldRange.TopRow, e.NewRange.TopRow); int r2 = Math.Max(e.OldRange.BottomRow, e.NewRange.BottomRow); int c1 = _flex.Cols.Fixed; int c2 = _flex.Cols.Count - 1; _flex.Invalidate(r1, c1, r2, c2); }
// handle toolbar private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { // apply border to current selection if (e.Button == tbBorderOn) { // assign border style to selection CellRange rg = _flex.Selection; rg.Style = _flex.Styles["Border"]; } // remove border from current selection if (e.Button == tbBorderOff) { // remove border style from selection CellRange rg = _flex.Selection; rg.Style = null; } // change border color if (e.Button == tbBorderColor) { // show color picker dialog ColorDialog dlg = new ColorDialog(); dlg.Color = _bdrBrush.Color; // if the user clicked OK, set new border color if (dlg.ShowDialog() == DialogResult.OK) { _bdrBrush.Color = dlg.Color; } } // thicker/thinner outer border if (e.Button == tbIncreaseOut) { if (_bdrOutside < 10) { _bdrOutside++; } } if (e.Button == tbDecreaseOut) { if (_bdrOutside > 0) { _bdrOutside--; } } // thicker/thinner inner border if (e.Button == tbIncreaseIn) { if (_bdrInside < 10) { _bdrInside++; } } if (e.Button == tbDecreaseIn) { if (_bdrInside > 0) { _bdrInside--; } } // save current sheet (with borders) into an Excel file if (e.Button == tbExcel) { _c1xl.Clear(); _c1xl.DefaultFont = _flex.Font; XLSheet sheet = _c1xl.Sheets[0]; for (int c = 0; c < _flex.Cols.Count; c++) { // save column width (twips) sheet.Columns[c].Width = (int)(_flex.Cols[c].WidthDisplay / 96f * 1440); // save cells on this column for (int r = 0; r < _flex.Rows.Count; r++) { // save cell value sheet[r, c].Value = _flex[r, c]; // we only want cells with style set to "Border" CellStyle s = _flex.GetCellStyle(r, c); if (s == null || s.Name != "Border") { continue; } // get custom border widths for this cell // (depends on neighbor cells) Margins m = GetBorderMargins(r, c); // create stytle for this cell XLStyle xs = new XLStyle(_c1xl); if (m.Top > 0) { xs.BorderTop = GetLineStyle(m.Top); xs.BorderColorTop = _bdrBrush.Color; } if (m.Left > 0) { xs.BorderLeft = GetLineStyle(m.Left); xs.BorderColorLeft = _bdrBrush.Color; } if (m.Right > 0) { xs.BorderRight = GetLineStyle(m.Right); xs.BorderColorRight = _bdrBrush.Color; } if (m.Bottom > 0) { xs.BorderBottom = GetLineStyle(m.Bottom); xs.BorderColorBottom = _bdrBrush.Color; } sheet[r, c].Style = xs; } } // save book string fileName = Application.StartupPath + @"\borders.xls"; _c1xl.Save(fileName); System.Diagnostics.Process.Start(fileName); } // repaint control to show changes _flex.Invalidate(); }
// handle toolbar private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { // apply border to current selection if (e.Button == tbBorderOn) { // assign border style to selection CellRange rg = _flex.Selection; rg.Style = _flex.Styles["Border"]; } // remove border from current selection if (e.Button == tbBorderOff) { // remove border style from selection CellRange rg = _flex.Selection; rg.Style = null; } // change border color if (e.Button == tbBorderColor) { // show color picker dialog ColorDialog dlg = new ColorDialog(); dlg.Color = _bdrBrush.Color; // if the user clicked OK, set new border color if (dlg.ShowDialog() == DialogResult.OK) { _bdrBrush.Color = dlg.Color; } } // thicker/thinner outer border if (e.Button == tbIncreaseOut) { if (_bdrOutside < 10) { _bdrOutside++; } } if (e.Button == tbDecreaseOut) { if (_bdrOutside > 0) { _bdrOutside--; } } // thicker/thinner inner border if (e.Button == tbIncreaseIn) { if (_bdrInside < 10) { _bdrInside++; } } if (e.Button == tbDecreaseIn) { if (_bdrInside > 0) { _bdrInside--; } } // repaint control to show changes _flex.Invalidate(); }