Ejemplo n.º 1
0
        /// <summary>
        /// Method to hanlde the QueryCoveredRange event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void dataGrid_QueryCoveredRange(object sender, GridQueryCoveredRangeEventArgs e)
        {
            // Merging cells for flat grid
            var range = GetRange(e.GridColumn, e.RowColumnIndex.RowIndex, e.RowColumnIndex.ColumnIndex, e.Record);

            if (range == null)
            {
                return;
            }

            // While editing we need to remove the range.
            if (this.dataGrid.CoveredCells.IsInRange(range))
            {
                CoveredCellInfo coveredCellInfo = this.dataGrid.GetConflictRange(range);

                while (coveredCellInfo != null)
                {
                    if (isEditted)
                    {
                        this.dataGrid.CoveredCells.Remove(coveredCellInfo);
                        coveredCellInfo = this.dataGrid.GetConflictRange(range);
                        if (coveredCellInfo == null)
                        {
                            isEditted = false;
                        }
                    }
                }
            }

            e.Range   = range;
            e.Handled = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 为给定的覆盖单元格和行索引获取RowSpan
        /// Get RowSpan for the given covered cell and rowIndex
        /// </summary>
        /// <param name="currHeaderCell"></param>
        /// <param name="rowindex"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static int GetHeightIncrementationLimit(this SfDataGrid sfGrid, CoveredCellInfo currHeaderCell, int rowindex)
        {
            if (rowindex < 0 || sfGrid.RowGenerator.Items.Count == 0)
            {
                return(0);
            }

            int incrementHeightLevel = 0;
            var prevHeaderCells      = (sfGrid.RowGenerator.Items.FirstOrDefault(row => row.RowIndex == rowindex) as SpannedDataRow).CoveredCells;
            int index = -1;

            foreach (var prevCell in prevHeaderCells)
            {
                //WPF-24997 We need to skip certain covered cells from setting height level which is not deals previous covered cells.
                //Hence the below condition is added by comparing the left and right indexes of Current and Previous covered cells.
                index++;
                if ((prevCell.Left <= currHeaderCell.Right && prevCell.Right >= currHeaderCell.Left) || (prevCell.Left >= currHeaderCell.Right && prevCell.Right <= currHeaderCell.Left))
                {
                    break;
                }

                //if (prevHeaderCells.IndexOf(prevCell) == prevHeaderCells.Count - 1)
                if (index == prevHeaderCells.Count - 1)
                {
                    incrementHeightLevel++;
                    incrementHeightLevel += sfGrid.GetHeightIncrementationLimit(currHeaderCell, rowindex - 1);
                    break;
                }
            }

            if (prevHeaderCells.Count == 0)
            {
                incrementHeightLevel++;
                incrementHeightLevel += sfGrid.GetHeightIncrementationLimit(currHeaderCell, rowindex - 1);
            }

            return(incrementHeightLevel);
        }
Ejemplo n.º 3
0
        private CoveredCellInfo GetRange(GridColumn column, int rowIndex, int columnIndex, object rowData)
        {
            IPropertyAccessProvider reflector = null;

            reflector = dataGrid.View.GetPropertyAccessProvider();

            var    range = new CoveredCellInfo(columnIndex, columnIndex, rowIndex, rowIndex);
            object data  = reflector.GetFormattedValue(rowData, column.MappingName);

            GridColumn leftColumn  = null;
            GridColumn rightColumn = null;

            // total rows count.
            int recordsCount = this.dataGrid.GroupColumnDescriptions.Count != 0 ?
                               (this.dataGrid.View.TopLevelGroup.DisplayElements.Count + this.dataGrid.TableSummaryRows.Count + this.dataGrid.UnBoundRows.Count + (this.dataGrid.AddNewRowPosition == AddNewRowPosition.Top ? +1 : 0)) :
                               (this.dataGrid.View.Records.Count + this.dataGrid.TableSummaryRows.Count + this.dataGrid.UnBoundRows.Count + (this.dataGrid.AddNewRowPosition == AddNewRowPosition.Top ? +1 : 0));

            // Merge Horizontally

            // compare right column

            for (int i = dataGrid.Columns.IndexOf(column); i < this.dataGrid.Columns.Count - 1; i++)
            {
                var compareData = reflector.GetFormattedValue(rowData, dataGrid.Columns[i + 1].MappingName);

                if (compareData == null)
                {
                    break;
                }

                if (!compareData.Equals(data))
                {
                    break;
                }
                rightColumn = dataGrid.Columns[i + 1];
            }

            // compare left column.

            for (int i = dataGrid.Columns.IndexOf(column); i > 0; i--)
            {
                var compareData = reflector.GetFormattedValue(rowData, dataGrid.Columns[i - 1].MappingName);

                if (compareData == null)
                {
                    break;
                }

                if (!compareData.Equals(data))
                {
                    break;
                }
                leftColumn = dataGrid.Columns[i - 1];
            }

            if (leftColumn != null || rightColumn != null)
            {
                // set left index

                if (leftColumn != null)
                {
                    var leftColumnIndex = this.dataGrid.ResolveToScrollColumnIndex(this.dataGrid.Columns.IndexOf(leftColumn));
                    range = new CoveredCellInfo(leftColumnIndex, range.Right, range.Top, range.Bottom);
                }

                // set right index

                if (rightColumn != null)
                {
                    var rightColumnIndex = this.dataGrid.ResolveToScrollColumnIndex(this.dataGrid.Columns.IndexOf(rightColumn));
                    range = new CoveredCellInfo(range.Left, rightColumnIndex, range.Top, range.Bottom);
                }
                return(range);
            }

            // Merge Vertically from the row index.

            int previousRowIndex = -1;
            int nextRowIndex     = -1;

            // Get previous row data.
            var startIndex = dataGrid.ResolveStartIndexBasedOnPosition();

            for (int i = rowIndex - 1; i >= startIndex; i--)
            {
                var previousData = this.dataGrid.GetRecordEntryAtRowIndex(i);

                if (previousData == null || !previousData.IsRecords)
                {
                    break;
                }
                var compareData = reflector.GetFormattedValue((previousData as RecordEntry).Data, column.MappingName);

                if (compareData == null)
                {
                    break;
                }

                if (!compareData.Equals(data))
                {
                    break;
                }
                previousRowIndex = i;
            }

            // get next row data.

            for (int i = rowIndex + 1; i < recordsCount + 1; i++)
            {
                var nextData = this.dataGrid.GetRecordEntryAtRowIndex(i);

                if (nextData == null || !nextData.IsRecords)
                {
                    break;
                }
                var compareData = reflector.GetFormattedValue((nextData as RecordEntry).Data, column.MappingName);

                if (compareData == null)
                {
                    break;
                }

                if (!compareData.Equals(data))
                {
                    break;
                }
                nextRowIndex = i;
            }

            if (previousRowIndex != -1 || nextRowIndex != -1)
            {
                if (previousRowIndex != -1)
                {
                    range = new CoveredCellInfo(range.Left, range.Right, previousRowIndex, range.Bottom);
                }

                if (nextRowIndex != -1)
                {
                    range = new CoveredCellInfo(range.Left, range.Right, range.Top, nextRowIndex);
                }
                return(range);
            }
            return(null);
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        private CoveredCellInfo GetRange(GridColumn column, int rowIndex, int columnIndex, object rowData) {
            var range = new CoveredCellInfo(columnIndex, columnIndex, rowIndex, rowIndex);
            object data = reflector.GetFormattedValue(rowData, column.MappingName);

            GridColumn leftColumn = null;
            GridColumn rightColumn = null;


            // total rows count.
            int recordsCount = this.sfDataGrid.GroupColumnDescriptions.Count != 0 ? (this.sfDataGrid.View.TopLevelGroup.DisplayElements.Count + 
                this.sfDataGrid.TableSummaryRows.Count + 
                this.sfDataGrid.UnBoundRows.Count + 
                (this.sfDataGrid.AddNewRowPosition == AddNewRowPosition.Top ? +1 : 0)) : (this.sfDataGrid.View.Records.Count + this.sfDataGrid.TableSummaryRows.Count + this.sfDataGrid.UnBoundRows.Count + (this.sfDataGrid.AddNewRowPosition == AddNewRowPosition.Top ? +1 : 0));

            // Merge Horizontally
            // compare right column               
            for (int i = sfDataGrid.Columns.IndexOf(column); i < this.sfDataGrid.Columns.Count - 1; i++) {
                var compareData = reflector.GetFormattedValue(rowData, sfDataGrid.Columns[i + 1].MappingName);

                if (compareData == null)
                    break;

                if (!compareData.Equals(data))
                    break;
                rightColumn = sfDataGrid.Columns[i + 1];
            }

            // compare left column.
            for (int i = sfDataGrid.Columns.IndexOf(column); i > 0; i--) {
                var compareData = reflector.GetFormattedValue(rowData, sfDataGrid.Columns[i - 1].MappingName);

                if (compareData == null)
                    break;

                if (!compareData.Equals(data))
                    break;
                leftColumn = sfDataGrid.Columns[i - 1];
            }

            if (leftColumn != null || rightColumn != null) {
                // set left index
                if (leftColumn != null) {
                    var leftColumnIndex = this.sfDataGrid.ResolveToScrollColumnIndex(this.sfDataGrid.Columns.IndexOf(leftColumn));
                    range = new CoveredCellInfo(leftColumnIndex, range.Right, range.Top, range.Bottom);
                }

                // set right index
                if (rightColumn != null) {
                    var rightColumIndex = this.sfDataGrid.ResolveToScrollColumnIndex(this.sfDataGrid.Columns.IndexOf(rightColumn));
                    range = new CoveredCellInfo(range.Left, rightColumIndex, range.Top, range.Bottom);
                }
                return range;
            }

            // Merge Vertically from the row index.

            int previousRowIndex = -1;
            int nextRowIndex = -1;

            // Get previous row data.                
            var startIndex = sfDataGrid.ResolveStartIndexBasedOnPosition();
            for (int i = rowIndex - 1; i > startIndex; i--) {
                var previousData = this.sfDataGrid.GetRecordEntryAtRowIndex(i);
                if (previousData == null || !previousData.IsRecords)
                    break;

                var compareData = reflector.GetFormattedValue((previousData as RecordEntry).Data, column.MappingName);

                if (compareData == null)
                    break;

                if (!compareData.Equals(data))
                    break;
                previousRowIndex = i;
            }

            // get next row data.
            for (int i = rowIndex + 1; i < recordsCount + 1; i++) {
                var nextData = this.sfDataGrid.GetRecordEntryAtRowIndex(i);
                if (nextData == null || !nextData.IsRecords)
                    break;

                var compareData = reflector.GetFormattedValue((nextData as RecordEntry).Data, column.MappingName);

                if (compareData == null)
                    break;

                if (!compareData.Equals(data))
                    break;
                nextRowIndex = i;
            }

            if (previousRowIndex != -1 || nextRowIndex != -1) {
                if (previousRowIndex != -1)
                    range = new CoveredCellInfo(range.Left, range.Right, previousRowIndex, range.Bottom);

                if (nextRowIndex != -1)
                    range = new CoveredCellInfo(range.Left, range.Right, range.Top, nextRowIndex);
                return range;
            }

            return null;
        }