public void SetSource(ITreeDataSource source, IBackend sourceBackend) { this.source = source; RowHeights.Clear(); tsource = new TreeSource(source); Tree.DataSource = tsource; source.NodeInserted += (sender, e) => Tree.ReloadItem(tsource.GetItem(source.GetParent(e.Node)), true); source.NodeDeleted += (sender, e) => Tree.ReloadItem(tsource.GetItem(e.Node), true); source.NodeChanged += (sender, e) => { var item = tsource.GetItem(e.Node); Tree.ReloadItem(item, false); UpdateRowHeight(item); }; source.NodesReordered += (sender, e) => Tree.ReloadItem(tsource.GetItem(e.Node), true); source.Cleared += (sender, e) => Tree.ReloadData(); }
public CustomGridModel() { // Initial dimension RowCount = 1000; ColCount = 13; // initial row and column sizes Rows.DefaultSize = 18; Cols.DefaultSize = 70; Properties.GridLineColor = System.Drawing.Color.FromArgb(208, 215, 229); RowHeights[0] = 21; ColWidths[0] = 35; RowHeights.ResetModified(); ColWidths.ResetModified(); // fixed columns Cols.HeaderCount = 1; Cols.FrozenCount = 2; // standard base styles BaseStylesMap.RegisterStandardStyles(); GridStyleInfo standardStyle = BaseStylesMap["Standard"].StyleInfo; standardStyle.MergeCell = GridMergeCellDirection.RowsInColumn; GridStyleInfo rowHeaderStyle = BaseStylesMap["Row Header"].StyleInfo; //rowHeaderStyle.CellType = "Static"; rowHeaderStyle.MergeCell = GridMergeCellDirection.RowsInColumn; BaseStylesMap.Modified = false; CellModels.Add("CustomCell", new CustomCellModel(this)); // Other options Options.MergeCellsMode = GridMergeCellsMode.OnDemandCalculation | GridMergeCellsMode.MergeRowsInColumn; Options.SmoothControlResize = false; // At the momemnt the Excel-like selection feature is broken when using merge cells. Options.ExcelLikeCurrentCell = false; Options.ExcelLikeSelectionFrame = false; Options.GridVisualStyles = GridVisualStyles.Office2007Blue; Options.DefaultGridBorderStyle = GridBorderStyle.Solid; }
public PerformanceGridModel() { CommandStack.Enabled = false; Rows.DefaultSize = 17; Cols.DefaultSize = 65; RowHeights[0] = 21; ColWidths[0] = 35; RowHeights.ResetModified(); ColWidths.ResetModified(); Options.ExcelLikeCurrentCell = false; Options.ExcelLikeSelectionFrame = false; Options.AllowDragSelectedCols = false; Options.AllowDragSelectedRows = false; CommandStack.Enabled = false; Options.FloatCellsMode = GridFloatCellsMode.None; BaseStylesMap.RegisterStandardStyles(); }
public static Grid Grid(RowHeights rowHeights, ColumnWidths columnWidths, params Xaml.UIElement[] children) { var grid = Grid(children); foreach (var height in rowHeights.Lengths) { grid.UI.RowDefinitions.Add(new Controls.RowDefinition { Height = height }); } foreach (var width in columnWidths.Lengths) { grid.UI.ColumnDefinitions.Add(new Controls.ColumnDefinition { Width = width }); } return(grid); }
public void SetSource(ITreeDataSource source, IBackend sourceBackend) { this.source = source; RowHeights.Clear(); tsource = new TreeSource(source); Tree.DataSource = tsource; source.NodeInserted += (sender, e) => { var parent = tsource.GetItem(source.GetParent(e.Node)); Tree.ReloadItem(parent, parent == null || Tree.IsItemExpanded(parent)); }; source.NodeDeleted += (sender, e) => { var parent = tsource.GetItem(e.Node); var item = tsource.GetItem(e.Child); if (item != null) { RowHeights.Remove(null); } Tree.ReloadItem(parent, parent == null || Tree.IsItemExpanded(parent)); }; source.NodeChanged += (sender, e) => { var item = tsource.GetItem(e.Node); if (item != null) { Tree.ReloadItem(item, false); UpdateRowHeight(item); } }; source.NodesReordered += (sender, e) => { var parent = tsource.GetItem(e.Node); Tree.ReloadItem(parent, parent == null || Tree.IsItemExpanded(parent)); }; source.Cleared += (sender, e) => { Tree.ReloadData(); RowHeights.Clear(); }; }
public static Grid Grid(RowHeights rowHeights, params Xaml.UIElement[] children) => Grid(rowHeights, Columns(), children);
public SampleGridControl() { GridCellNestedGridModel gridModel = new GridCellNestedGridModel(GridNestedAxisLayout.Normal, GridNestedAxisLayout.Normal); GridCellNestedScrollGridModel scrollGridModel = new GridCellNestedScrollGridModel(); GridCellNestedGridModel shareRowLayoutGridModel = new GridCellNestedGridModel(GridNestedAxisLayout.Shared, GridNestedAxisLayout.Normal); GridCellNestedGridModel shareColumnLayoutGridModel = new GridCellNestedGridModel(GridNestedAxisLayout.Normal, GridNestedAxisLayout.Shared); GridCellNestedGridModel gridInRowModel = new GridCellNestedGridModel(GridNestedAxisLayout.Nested, GridNestedAxisLayout.Normal); Model.CellModels.Add("Grid", gridModel); Model.CellModels.Add("ScrollGrid", scrollGridModel); Model.CellModels.Add("ShareRowLayoutGrid", shareRowLayoutGridModel); Model.CellModels.Add("ShareColumnLayoutGrid", shareColumnLayoutGridModel); Model.CellModels.Add("GridInRow", gridInRowModel); #region Sample Setup RowHeights.DefaultLineSize = 20; Model.RowCount = 6000; ColumnWidths.DefaultLineSize = 100; Model.ColumnCount = 20; Random buttonRandom = new Random(23); Random orangePenRandom = new Random(2); Random backBrushRandom = new Random(18); gridLinePen = new Pen(Brushes.DarkGray, 1); gridLinePen.Freeze(); Pen orangePen = new Pen(Brushes.DarkOrange, 5); orangePen.EndLineCap = PenLineCap.Triangle; orangePen.StartLineCap = PenLineCap.Triangle; orangePen.Freeze(); Pen bgPen = new Pen(Brushes.Gold, 6); bgPen.EndLineCap = PenLineCap.Triangle; bgPen.StartLineCap = PenLineCap.Triangle; bgPen.Freeze(); SolidColorBrush bg1 = new SolidColorBrush(Color.FromArgb(128, 128, 0, 0)); SolidColorBrush bg2 = new SolidColorBrush(Color.FromArgb(128, 0, 128, 0)); SolidColorBrush bg3 = new SolidColorBrush(Color.FromArgb(128, 0, 0, 128)); GradientBrush bg = new LinearGradientBrush(Color.FromArgb(128, 255, 255, 0), Color.FromArgb(128, 0, 255, 255), 45.0); //GradientBrush bg = new LinearGradientBrush(Colors.Gray, Colors.White, 45); CellSpanBackgrounds.Add(new CellSpanBackgroundInfo(9, 2, 22, 8, false, false, bg1, bgPen)); CellSpanBackgrounds.Add(new CellSpanBackgroundInfo(3, 4, 28, 6, false, false, bg2, bgPen)); CellSpanBackgrounds.Add(new CellSpanBackgroundInfo(25, 2, 30, 4, false, false, bg3, bgPen)); CellSpanBackgrounds.Add(new CellSpanBackgroundInfo(0, 0, 12, 1, false, false, bg, null)); CoveredCells.Add(new CoveredCellInfo(4, 0, 6, 1)); CoveredCells.Add(new CoveredCellInfo(4, 19, 6, 19)); CoveredCells.Add(new CoveredCellInfo(6, 2, 8, 4)); CoveredCells.Add(new CoveredCellInfo(4, 2, 5, 3)); Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo); for (int n = 0; n < Model.RowCount; n++) { for (int c = 0; c < Model.ColumnCount; c++) { GridStyleInfo ci = new GridStyleInfo(); if (backBrushRandom.Next(10) == 5) { ci.Background = Brushes.Tomato; } if (c == 5)//% 4 == 3)// || c == 5) { ci.CellType = "CheckBox"; ci.Description = String.Format("Check {0}:{1}", n, c); ci.CellValue = n % 2 == 0; } if (c == 2) { ci.CellType = "TextBox"; ci.CellValue = String.Format("Edit {0}:{1}", n, c); } if (buttonRandom.Next(10) == 5) { ci.CellType = "Button"; ci.Description = String.Format("Click {0}:{1}", n, c); ci.Background = null; } if (orangePenRandom.Next(10) == 5) { ci.Borders.Right = orangePen; ci.Borders.Bottom = orangePen; ci.Borders.Left = orangePen; ci.Borders.Top = orangePen; //ci.BorderMargins.Right = orangePen.Thickness / 2; //ci.BorderMargins.Bottom = orangePen.Thickness / 2; //ci.BorderMargins.Top = orangePen.Thickness / 2; //ci.BorderMargins.Left = orangePen.Thickness / 2; } if (!ci.IsEmpty) { //if (n == Model.RowCount - 1 && c == Model.ColCount - 1) // Console.WriteLine("ddd"); Model[n, c].Background = Brushes.Red; Model[n, c] = ci; } } } if (true) { Model[6, 2].CellType = "Grid"; //Model[6, 2].CellRenderer = gridRenderer; Model[6, 2].CellValue = GetSimpleNestedGrid(); } if (true) { CoveredCellInfo coveredCell1 = new CoveredCellInfo(36, 0, 36, Model.ColumnCount - 1); coveredCell1.SpanWholeRow = true; CoveredCells.Add(coveredCell1); Model[36, 0].CellType = "GridInRow"; //Model[36, 0].CellRenderer = gridInRowRenderer; GridModel m = GetSimpleNestedGrid(); Model[36, 0].CellValue = m; //PixelScrollAxis mb = new PixelScrollAxis(new ScrollInfo(), m.RowHeights); RowHeights.SetNestedLines(36, m.RowHeights);//.Distances;//.TotalDistance GridModel m2 = GetSimpleNestedGrid(); m[5, 1].Background = new SolidColorBrush(Colors.LightCoral); m[5, 1].CellValue = m2; m2.ColumnWidths.DefaultLineSize = 65; m[5, 1].CellType = "GridInRow"; //m[5, 1].CellRenderer = gridInRowRenderer; m.RowHeights.SetNestedLines(5, m2.RowHeights); m.CoveredCells.Add(new CoveredCellInfo(5, 1, 5, 6)); } if (true) { Model[40, 2].CellType = "ScrollGrid"; //Model[40, 2].CellRenderer = scrollGridRenderer; Model[40, 2].CellValue = GetScrollNestedGrid(); CoveredCells.Add(new CoveredCellInfo(40, 2, 49, 5)); } if (true) { Model[60, 1].CellType = "ShareColumnLayoutGrid"; //Model[60, 1].CellRenderer = shareColumnLayoutGridRenderer; Model[60, 1].BorderMargins.Top = 0; Model[60, 1].BorderMargins.Left = 0; Model[60, 1].BorderMargins.Right = 0; Model[60, 1].BorderMargins.Bottom = 0; Model[60, 1].Background = SystemColors.InactiveCaptionBrush; GridModel nestedGridWithSharedColumnsModel = GetNestedGridWithSharedColumnsModel(); Model[60, 1].CellValue = nestedGridWithSharedColumnsModel; CoveredCells.Add(new CoveredCellInfo(60, 1, 80, 1 + nestedGridWithSharedColumnsModel.ColumnCount - 1)); } if (true) { Model[100, 2].CellType = "ShareRowLayoutGrid"; //Model[100, 2].CellRenderer = shareRowLayoutGridRenderer; Model[100, 2].BorderMargins.Top = 0; Model[100, 2].BorderMargins.Left = 0; Model[100, 2].BorderMargins.Right = 0; Model[100, 2].BorderMargins.Bottom = 0; Model[100, 2].Background = SystemColors.InactiveCaptionBrush; GridModel nestedGridWithSharedRowsModel = GetNestedGridWithSharedRowsModel(); Model[100, 2].CellValue = nestedGridWithSharedRowsModel; CoveredCells.Add(new CoveredCellInfo(100, 2, 100 + nestedGridWithSharedRowsModel.RowCount - 1, 5)); Random rnd = new Random(120); for (int n = 0; n < 100; n++) { RowHeights[rnd.Next(Model.RowCount)] = rnd.Next(10, 50); } for (int n = 0; n < 5; n++) { ColumnWidths[rnd.Next(Model.ColumnCount)] = rnd.Next(40, 400); } } RowHeights.SetHidden(10, 20, true); FrozenRows = 2; FrozenColumns = 1; FooterColumns = 1; FooterRows = 1; Console.WriteLine(FrozenRows); Console.WriteLine(FrozenColumns); #endregion GridStyleInfo tableStyle = Model.TableStyle; GridStyleInfo headerStyle = Model.HeaderStyle; GridStyleInfo footerStyle = Model.FooterStyle; tableStyle.CellType = "TextBox"; tableStyle.BorderMargins.Top = gridLinePen.Thickness; tableStyle.BorderMargins.Left = gridLinePen.Thickness; tableStyle.BorderMargins.Right = gridLinePen.Thickness / 2; tableStyle.BorderMargins.Bottom = gridLinePen.Thickness / 2; tableStyle.Borders.Right = gridLinePen; tableStyle.Background = null;// Brushes.White; tableStyle.Borders.Bottom = gridLinePen; headerStyle.Background = SystemColors.ControlBrush; headerStyle.CellType = "Static"; footerStyle.Background = Brushes.Wheat; }
/*private void CellOnPointerReleased(object sender, PointerReleasedEventArgs e) * { * if (e.InitialPressMouseButton == MouseButton.Left) * { * Cell cell = (Cell)sender; * GridControl.UpdateSelection(cell); * } * }*/ protected override Size MeasureOverride(Size availableSize) { if (GridControl.Columns.Count == 0 || GridControl.Controller.Count == 0) { foreach (var cell in Cells.GetVisibleCells()) { cell.IsVisible = false; } for (int i = 0; i < RowHeights.Count; i++) { RowHeights[i] = Double.NaN; } CalcAccumulatedColumnRowSizes(); ScrollBar.IsVisible = false; return(Size.Empty); } start: bool measureFromTop = (bottomRowToFocus < 0); if (measureFromTop) { for (int i = 0; i < RowHeights.Count; i++) { RowHeights[i] = 0.0; } } else { RowHeights.Clear(); } double offsetFloor = Math.Floor(ScrollBar.Value); int firstRow = Convert.ToInt32(offsetFloor); int row = firstRow - 1; if (!measureFromTop) { firstRow = bottomRowToFocus; row = firstRow + 1; bottomRowToFocus = -1; } Cells.SetInitialRow(firstRow); double viewportRowsHeight = measureFromTop ? 0.0 : GridControl.HorizontalLinesThickness; double firstVisibleRowVisiblePart = 1.0; double lastVisibleRowVisiblePart = 1.0; FirstWholeVisibleRow = LastWholeVisibleRow = -1; //TODO zero, very big one and two rows while (viewportRowsHeight < availableSize.Height) { if (measureFromTop) { if (row == GridControl.Controller.Count - 1) { break; } row++; } else { if (row == 0) { break; } row--; } int visibleRowIndex = Math.Abs(row - firstRow); for (int column = 0; column < GridControl.Columns.Count; column++) { bool cellNeedsMeasure = false; var cell = Cells.GetCell(row - firstRow, column); if (cell.Row != row) { cell.Row = row; cell.DataContext = GridControl.Controller.GetProperty(row, GridControl.Columns[column].FieldName); cellNeedsMeasure = true; } if (!cell.IsVisible) { cell.IsVisible = true; cellNeedsMeasure = true; } if (cellNeedsMeasure) { //UpdateCellSelection(cell); cell.InvalidateMeasure(); cell.Measure(Size.Infinity); } if (visibleRowIndex == RowHeights.Count) { RowHeights.Add(0.0); } RowHeights[visibleRowIndex] = Math.Max(RowHeights[visibleRowIndex], cell.DesiredSize.Height); } viewportRowsHeight += RowHeights[visibleRowIndex]; if (measureFromTop && visibleRowIndex == 0) { double firstRowHiddenPart = ScrollBar.Value - offsetFloor; firstVisibleRowVisiblePart = 1.0 - firstRowHiddenPart; viewportRowsHeight *= firstVisibleRowVisiblePart; AccumulatedRowHeightsStart = -RowHeights[0] * firstRowHiddenPart; } if (viewportRowsHeight >= availableSize.Height) { double visibleRowVisiblePart = (RowHeights[visibleRowIndex] - (viewportRowsHeight - availableSize.Height)) / RowHeights[visibleRowIndex]; if (measureFromTop) { lastVisibleRowVisiblePart = visibleRowVisiblePart; } else { firstVisibleRowVisiblePart = visibleRowVisiblePart; double firstRowHiddenPart = 1.0 - firstVisibleRowVisiblePart; AccumulatedRowHeightsStart = -RowHeights[RowHeights.Count - 1] * firstRowHiddenPart; } } viewportRowsHeight += GridControl.HorizontalLinesThickness; } if (row < 0) { ScrollBar.Value = 0.0; goto start; } if (!measureFromTop) { //TODO top grid line is not drawn if it should and we have one pixel of next raw in the bottom int temp = firstRow; firstRow = row; row = temp; Cells.SetInitialRow(firstRow); RowHeights.Reverse(); ScrollBar.Value = firstRow + (1.0 - firstVisibleRowVisiblePart); } FirstWholeVisibleRow = firstRow; if (firstVisibleRowVisiblePart < 1.0) { FirstWholeVisibleRow++; } LastWholeVisibleRow = row; if (lastVisibleRowVisiblePart < 1.0) { LastWholeVisibleRow--; } if (FirstWholeVisibleRow > LastWholeVisibleRow) { //TODO check that all works with this FirstWholeVisibleRow = LastWholeVisibleRow = -1; } //TODO fix bug when row == GridControl.Controller.Count Cells.OptimizeFreeCells(row + 1); Cells.UpdateVisibility(row + 1); for (int i = row - firstRow + 1; i < RowHeights.Count; i++) { RowHeights[i] = Double.NaN; } CalcAccumulatedColumnRowSizes(); UpdateScrollBar(); return(new Size(AccumulatedColumnWidths[AccumulatedColumnWidths.Count - 1], viewportRowsHeight)); void CalcAccumulatedColumnRowSizes() { var columns = GridControl.Columns; if (AccumulatedColumnWidths.Count > columns.Count + 1) { AccumulatedColumnWidths.RemoveRange(columns.Count + 1, AccumulatedColumnWidths.Count - (columns.Count + 1)); } if (columns.Count + 1 > AccumulatedColumnWidths.Count) { AccumulatedColumnWidths.AddRange(Enumerable.Repeat(0.0, columns.Count + 1 - AccumulatedColumnWidths.Count)); } for (int i = 0; i < AccumulatedColumnWidths.Count; i++) { if (i != 0) { AccumulatedColumnWidths[i] = AccumulatedColumnWidths[i - 1] + columns[i - 1].Width + GridControl.VerticalLinesThickness; } else { AccumulatedColumnWidths[i] = 0.0; } } if (AccumulatedRowHeights.Count > RowHeights.Count + 1) { AccumulatedRowHeights.RemoveRange(RowHeights.Count + 1, AccumulatedRowHeights.Count - (RowHeights.Count + 1)); } if (RowHeights.Count + 1 > AccumulatedRowHeights.Count) { AccumulatedRowHeights.AddRange(Enumerable.Repeat(0.0, RowHeights.Count + 1 - AccumulatedRowHeights.Count)); } for (int i = 0; i < AccumulatedRowHeights.Count; i++) { if (i != 0) { if (!Double.IsNaN(RowHeights[i - 1])) { AccumulatedRowHeights[i] = Math.Round(AccumulatedRowHeights[i - 1] + RowHeights[i - 1] + GridControl.HorizontalLinesThickness); } else { AccumulatedRowHeights[i] = Double.NaN; } } else { AccumulatedRowHeights[i] = Math.Round(AccumulatedRowHeightsStart); if (AccumulatedRowHeightsStart < -Single.Epsilon) { AccumulatedRowHeights[i] += GridControl.HorizontalLinesThickness; } } } } void UpdateScrollBar() { //TODO: grid should not scroll entirely ScrollBar.IsVisible = (viewportRowsHeight >= availableSize.Height); ScrollBar.Height = availableSize.Height; ScrollBar.ViewportSize = row - firstRow - 2 + firstVisibleRowVisiblePart + lastVisibleRowVisiblePart; ScrollBar.InvalidateMeasure(); ScrollBar.Measure(Size.Infinity); } }
public ExcelSheet SetRowHeight(params RowHeight[] rowHeights) { RowHeights.AddRange(rowHeights); return(this); }