Ejemplo n.º 1
0
 /// <summary>
 /// Initialize a new object.
 /// </summary>
 /// <param name="rowIndex">The row index.</param>
 /// <param name="colIndex">The column index.</param>
 /// <param name="range">A <see cref="CoveredCellInfo"/> that will receive the resulting range for the covered cell.</param>
 public GridQueryCoveredRangeEventArgs(RowColumnIndex cellRowColumnIndex, CoveredCellInfo range, GridColumn column, object record, object originalSource) : base(originalSource)
 {
     this.range = range;
     this.cellRowColumnIndex = cellRowColumnIndex;
     this.column             = column;
     this.record             = record;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the conflicting range from existing CoveredCells collection.
 /// </summary>
 /// <param name="coveredCellInfo">Specifies the range that conflicting with existing covered ranges</param>
 /// <returns>Returns the covered cell range if the given range is conflicting any other existing range of CoveredCells. </returns>
 public static CoveredCellInfo GetConflictRange(this SfDataGrid dataGrid, CoveredCellInfo coveredCellInfo)
 {
     foreach (CoveredCellInfo coveredCell in dataGrid.CoveredCells)
     {
         // Reference - condition based on Rectangle clip check from MS.
         if (coveredCell.Top <= coveredCellInfo.Bottom &&
             coveredCell.Bottom >= coveredCellInfo.Top &&
             coveredCell.Right >= coveredCellInfo.Left &&
             coveredCell.Left <= coveredCellInfo.Right)
         {
             return(coveredCell);
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
        private SpannedDataColumn CreateColumn(CoveredCellInfo cc, int index, int heightIncrementation, int widthIncrementation)
        {
            var dc = new SpannedDataColumn
            {
                ColumnIndex = index,
                RowSpan     = heightIncrementation,
                ColumnSpan  = widthIncrementation,
                // WPF-19238- if grid has no columns and summary row is added, need to set null for grid column
                GridColumn          = this.DataGrid.Columns.Count > 0 ? this.DataGrid.Columns[ResolveToGridColumnIndex(index)] : null,
                RowIndex            = this.RowIndex,
                SelectionController = this.DataGrid.SelectionController
            };

            if (this.RowType == RowType.TableSummaryRow || this.RowType == RowType.TableSummaryCoveredRow)
            {
                dc.Renderer = this.DataGrid.CellRenderers["TableSummary"];
            }
            else if (this.RowType == RowType.CaptionRow || this.RowType == RowType.CaptionCoveredRow)
            {
                dc.Renderer = this.DataGrid.CellRenderers["CaptionSummary"];
            }
            else if (this.RowType == Grid.RowType.HeaderRow)
            {
                if (dc.RowIndex < this.DataGrid.GetHeaderIndex())
                {
                    dc.GridColumn = null;
                    dc.Renderer   = this.DataGrid.CellRenderers["StackedHeader"];
                    this.RowData  = this.DataGrid.StackedHeaderRows[this.RowIndex].StackedColumns.FirstOrDefault(col => col.HeaderText == cc.Name);
                }
                else
                {
                    dc.Renderer = this.DataGrid.CellRenderers["Header"];
                }
            }
            else //(this.RowType == RowType.SummaryRow || this.RowType == RowType.SummaryCoveredRow)
            {
                dc.Renderer = this.DataGrid.CellRenderers["GroupSummary"];
            }

            dc.InitializeColumnElement(this.RowData, false);
#if WPF
            if (DataGrid.useDrawing && dc.ColumnElement is GridCell)
            {
                (dc.ColumnElement as GridCell).UseDrawing = DataGrid.useDrawing;
            }
#endif
            return(dc);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Add the range to CoveredCells.
        /// </summary>
        /// <param name="dataGrid">The SfDataGrid.</param>
        /// <param name="coveredCellRange">Specifies the range that will added to CoveredCells</param>
        public static void AddRange(this SfDataGrid dataGrid, CoveredCellInfo coveredCellRange)
        {
            if (dataGrid.CoveredCells.IsInRange(coveredCellRange))
            {
                throw new Exception(String.Format("Conflict detected with when trying to save {0}", coveredCellRange));
            }

            coveredCellRange.MappedRowColumnIndex = new RowColumnIndex(coveredCellRange.Top, coveredCellRange.Left);

            dataGrid.CoveredCells.Add(coveredCellRange);
            dataGrid.RowGenerator.Items.ForEach(row =>
            {
                if ((row.RowType == RowType.UnBoundRow || row.RowType == RowType.DefaultRow) && row.RowIndex >= coveredCellRange.Top && row.RowIndex <= coveredCellRange.Bottom)
                {
                    dataGrid.MergedCellManager.InitializeMergedRow(row);
                }
            });
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Remove the range from CoveredCells.
        /// </summary>
        /// <param name="dataGrid">The SfDataGrid.</param>
        /// <param name="coveredCellRange">Specifies the range to remove from CoveredCells</param>
        public static void RemoveRange(this SfDataGrid dataGrid, CoveredCellInfo coveredCellRange)
        {
            var conatins = dataGrid.CoveredCells.Contains(coveredCellRange);

            if (!conatins)
            {
                return;
            }

            // Find range from the covered cells.
            var resetRange = dataGrid.CoveredCells.Find(range => coveredCellRange.Top >= range.Top && coveredCellRange.Bottom <= range.Bottom && coveredCellRange.Left >= range.Left && coveredCellRange.Right <= range.Right);

            if (resetRange == null)
            {
                return;
            }

            dataGrid.CoveredCells.Remove(resetRange);
            dataGrid.RowGenerator.Items.ForEach(row =>
            {
                if (row.RowIndex >= resetRange.Top && row.RowIndex <= resetRange.Bottom)
                {
                    row.RowIndex = -1;
                    dataGrid.MergedCellManager.ResetCoveredRows(row);
                }
            });

            if (!(resetRange.Top == coveredCellRange.Top || resetRange.Bottom == coveredCellRange.Bottom))
            {
                throw new Exception(string.Format("Given range {0} is not valid to remove from the range {1}", coveredCellRange, resetRange));
            }

            if (resetRange.Top == coveredCellRange.Top && resetRange.Bottom == coveredCellRange.Bottom)
            {
                return;
            }

            resetRange = new CoveredCellInfo(resetRange.Left, resetRange.Right, resetRange.Top == coveredCellRange.Top ? coveredCellRange.Bottom : resetRange.Top, resetRange.Bottom == coveredCellRange.Bottom ? coveredCellRange.Top : resetRange.Bottom);
            resetRange.MappedRowColumnIndex = new RowColumnIndex(resetRange.Top, resetRange.Left);
            dataGrid.CoveredCells.Add(resetRange);
        }
Ejemplo n.º 6
0
        internal override void EnsureColumns(VisibleLinesCollection visibleColumnLines)
        {
            if (this.RowIndex == -1)
            {
                this.RowLevel = -1;
                return;
            }
            this.VisibleColumns.ForEach(column => column.IsEnsured = false);
            var StartBodyColumnIndex = (visibleColumnLines.firstBodyVisibleIndex < visibleColumnLines.Count) ? visibleColumnLines[visibleColumnLines.firstBodyVisibleIndex].LineIndex : visibleColumnLines[visibleColumnLines.LastBodyVisibleIndex].LineIndex;

            if (this.CoveredCells.Count > 0 || this.RowIndex < this.DataGrid.HeaderLineCount)
            {
                for (int i = 0; i < 3; i++)
                {
                    int startColumnIndex;
                    int endColumnIndex;
                    if (i == 0)
                    {
                        if (visibleColumnLines.FirstBodyVisibleIndex <= 0)
                        {
                            continue;
                        }
                        startColumnIndex = 0;
                        endColumnIndex   = visibleColumnLines[visibleColumnLines.FirstBodyVisibleIndex - 1].LineIndex;
                    }
                    else if (i == 1)
                    {
                        if (visibleColumnLines.FirstBodyVisibleIndex <= 0 && visibleColumnLines.LastBodyVisibleIndex < 0)
                        {
                            continue;
                        }
                        if (visibleColumnLines.Count > visibleColumnLines.firstBodyVisibleIndex)
                        {
                            startColumnIndex = visibleColumnLines[visibleColumnLines.FirstBodyVisibleIndex].LineIndex;
                        }
                        else
                        {
                            continue;
                        }
                        endColumnIndex = visibleColumnLines[visibleColumnLines.LastBodyVisibleIndex].LineIndex;
                    }
                    else
                    {
                        if (visibleColumnLines.FirstFooterVisibleIndex >= visibleColumnLines.Count)
                        {
                            continue;
                        }
                        startColumnIndex = visibleColumnLines[visibleColumnLines.FirstFooterVisibleIndex].LineIndex;
                        endColumnIndex   = visibleColumnLines[visibleColumnLines.Count - 1].LineIndex;
                    }

                    for (int index = startColumnIndex; index <= endColumnIndex; index++)
                    {
                        if (visibleColumnLines.All(row => row.LineIndex != index))
                        {
                            continue;
                        }
                        if (DataGrid.ShowRowHeader && index == 0)
                        {
                            var rhc = this.VisibleColumns.FirstOrDefault(column => column.ColumnIndex == index);
                            if (rhc != null)
                            {
                                if (rhc.ColumnVisibility == Visibility.Collapsed)
                                {
                                    rhc.ColumnVisibility = Visibility.Visible;
                                }
                                rhc.IsEnsured = true;
                            }
                            else
                            {
                                CreateRowHeaderColumn(index);
                            }
                            continue;
                        }
                        if (this.DataGrid.View != null && this.DataGrid.DetailsViewManager.HasDetailsView && index == (this.DataGrid.ShowRowHeader ? this.DataGrid.View.GroupDescriptions.Count + 1 : this.DataGrid.View.GroupDescriptions.Count))
                        {
                            var dvc = this.VisibleColumns.FirstOrDefault(column => column.ColumnIndex == index);
                            if (dvc != null)
                            {
                                if (dvc.ColumnVisibility == Visibility.Collapsed)
                                {
                                    dvc.ColumnVisibility = Visibility.Visible;
                                }
                                dvc.IsEnsured = true;
                                continue;
                            }

                            if (this.RowIndex < this.DataGrid.StackedHeaderRows.Count)
                            {
                                this.VisibleColumns.Add(this.CreateIndentColumn(index));
                            }
                            else if (this.RowType == RowType.SummaryRow || this.RowType == RowType.CaptionRow ||
                                     this.RowType == RowType.TableSummaryRow)
                            {
                                this.VisibleColumns.Add(CreateDetailsViewIndentColumn(index));
                            }
                            continue;
                        }

                        var rowHeaderIndex  = this.DataGrid.ShowRowHeader ? 1 : 0;
                        var indentCellIndex = -1;
                        if (this.RowType == RowType.CaptionCoveredRow)
                        {
                            indentCellIndex = this.DataGrid.View != null ? this.RowLevel + rowHeaderIndex : rowHeaderIndex;
                        }
                        else
                        {
                            indentCellIndex = this.DataGrid.View != null ? this.DataGrid.View.GroupDescriptions.Count + rowHeaderIndex : rowHeaderIndex;
                        }

                        if (index < indentCellIndex)
                        {
                            this.EnsureIndentColumns(visibleColumnLines, index);
                            this.CheckAvailablity(index, true);
                            continue;
                        }
                        else
                        {
                            CoveredCellInfo coveredCellItem = null;
                            if (this.RowType == RowType.CaptionCoveredRow || this.RowType == RowType.SummaryCoveredRow || this.RowType == RowType.TableSummaryCoveredRow)
                            {
                                coveredCellItem = this.CoveredCells.FirstOrDefault();
                            }
                            else
                            {
                                coveredCellItem = this.CoveredCells.FirstOrDefault(item => item.Left <= index && item.Right >= index);
                            }
                            var actualIndex = coveredCellItem != null ? coveredCellItem.Left : index;
                            if ((this.RowRegion == RowRegion.Body || RowType == RowType.TableSummaryCoveredRow || RowType == RowType.TableSummaryRow) && this.VisibleColumns.All(column => column.ColumnIndex != actualIndex))
                            {
                                if (this.VisibleColumns.Any(column => ((column.ColumnIndex < StartBodyColumnIndex || column.ColumnIndex > endColumnIndex) && !column.IsEnsured && !column.IsIndentColumn)))
                                {
                                    var datacolumn = this.VisibleColumns.FirstOrDefault(column => ((column.ColumnIndex <StartBodyColumnIndex || column.ColumnIndex> endColumnIndex) && !column.IsEnsured && !column.IsIndentColumn && column.Renderer != null && column.Renderer != this.DataGrid.CellRenderers["RowHeader"]));
                                    if (datacolumn != null)
                                    {
                                        UpdateColumn(datacolumn, index);
                                    }
                                }
                            }
                            this.CheckAvailablity(actualIndex, false);
                        }
                    }
                }
                var orderedColumns = this.VisibleColumns.OrderBy(item => item.ColumnIndex);


                this.ResetLastColumnBorderThickness(orderedColumns.LastOrDefault(col =>
                {
                    if ((col.ColumnElement is GridGroupSummaryCell || col.ColumnElement is GridTableSummaryCell ||
                         col.ColumnElement is GridCaptionSummaryCell) && col.ColumnElement.Visibility != Visibility.Collapsed)
                    {
                        if (col.ColumnSpan > 0)
                        {
                            return(true);
                        }
                        else
                        {
                            return(col.GridColumn != null && !col.GridColumn.IsHidden);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }), true);
            }

            if (this.RowType != Grid.RowType.TableSummaryRow || this.RowType != Grid.RowType.TableSummaryCoveredRow)
            {
                if (this.IsSelectedRow)
                {
                    this.WholeRowElement.UpdateSelectionBorderClip();
                }
                //When scrolling horizontally the Focus border margin is not changed which sets the margin including the IndentCell Width,
                //hence the below code is added.
                else if (this.IsCurrentRow && this.DataGrid.SelectionMode == GridSelectionMode.Multiple)
                {
                    this.WholeRowElement.UpdateFocusRowPosition();
                }
            }
            this.VisibleColumns.ForEach(column =>
            {
                if (!column.IsEnsured)
                {
                    CollapseColumn(column);
                }
            });
            this.InvalidateMeasure();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Raise query for the each column
        /// </summary>
        /// <param name="dataGrid"></param>
        /// <param name="dc"></param>
        internal void EnsureMergedCells(DataRowBase dr, DataColumnBase dc, object dataContext)
        {
            if (dc.GridColumn == null)
            {
                return;
            }

            var coveredCell = dataGrid.CoveredCells.GetCoveredCell(dc.RowIndex, dc.ColumnIndex, dc.GridColumn, dataContext);

            if (coveredCell == null)
            {
                return;
            }

            //Throws exception for invalid range with rows.
            this.dataGrid.CoveredCells.ContainsRow(coveredCell);
            // Throws exception for invalid range with columns.
            this.dataGrid.CoveredCells.ContainsColumn(dr, coveredCell);

            if (!dc.GridColumn.hasCellTemplate &&
                (dc.GridColumn.hasCellTemplateSelector ||
                 (dc.GridColumn.IsTemplate && ((dc.GridColumn as GridTemplateColumn).hasEditTemplateSelector || dataGrid.hasCellTemplateSelector))))

            // Column has cell template selector will not get merge.

            {
                this.dataGrid.CoveredCells.Remove(coveredCell);
                return;
            }

            // Raise exception for the invalid range of unbound row.
            if (dr.RowType == RowType.UnBoundRow)
            {
                var       bottomIndex  = coveredCell.Bottom;
                var       topIndex     = coveredCell.Top;
                RowRegion topRowRegion = dr.RowRegion;
                if (dataGrid.RowGenerator.Items.Find(row => row.RowIndex == topIndex) != null)
                {
                    topRowRegion = dataGrid.RowGenerator.Items.Find(row => row.RowIndex == topIndex).RowRegion;
                }
                RowRegion bottomRowRegion = dr.RowRegion;
                if (dataGrid.RowGenerator.Items.Find(row => row.RowIndex == bottomIndex) != null)
                {
                    bottomRowRegion = dataGrid.RowGenerator.Items.Find(row => row.RowIndex == bottomIndex).RowRegion;
                }
                if (!dataGrid.IsUnBoundRow(bottomIndex) || !dataGrid.IsUnBoundRow(topIndex) || topRowRegion != bottomRowRegion)
                {
                    throw new Exception(string.Format("Given range {0} is not valid", coveredCell));
                }
            }
            dr.isSpannedRow    = true;
            dc.isSpannedColumn = true;

            // Reset the covered cell  range by bottom for Frozen rows.
            if (dataGrid.FrozenRowsCount > 0 && coveredCell.Top < dataGrid.VisualContainer.FrozenRows)
            {
                CoveredCellInfo newCoveredCell = null;
                dataGrid.CoveredCells.Remove(coveredCell);
                if (coveredCell.Top < dataGrid.VisualContainer.FrozenRows && coveredCell.Bottom >= dataGrid.VisualContainer.FrozenRows)
                {
                    newCoveredCell = new CoveredCellInfo(coveredCell.Left,
                                                         coveredCell.Right,
                                                         coveredCell.Top,
                                                         coveredCell.Bottom < dataGrid.VisualContainer.FrozenRows ? coveredCell.Bottom : dataGrid.VisualContainer.FrozenRows - 1);
                }
                else
                {
                    newCoveredCell = coveredCell;
                }

                dataGrid.CoveredCells.Add(newCoveredCell);

                this.UpdateMappedRowIndex(dr, dr.RowIndex);

                dataGrid.RowGenerator.Items.ForEach(row =>
                {
                    if (newCoveredCell != null && row.RowIndex > newCoveredCell.Bottom && row.RowIndex <= coveredCell.Bottom)
                    {
                        dataGrid.MergedCellManager.ResetCoveredRows(row);
                    }
                }
                                                    );
            }

            //  Reset the covered cell range by top for footer rows.
            else if (dataGrid.FooterRowsCount > 0 && coveredCell.Bottom >= (this.dataGrid.VisualContainer.RowCount - this.dataGrid.VisualContainer.FooterRows) &&
                     coveredCell.Bottom < this.dataGrid.VisualContainer.RowCount)
            {
                CoveredCellInfo newCoveredCell = null;
                dataGrid.CoveredCells.Remove(coveredCell);
                if (coveredCell.Top < (dataGrid.VisualContainer.RowCount - dataGrid.VisualContainer.FooterRows))
                {
                    newCoveredCell = new CoveredCellInfo(coveredCell.Left,
                                                         coveredCell.Right,
                                                         coveredCell.Top < (dataGrid.VisualContainer.RowCount - dataGrid.VisualContainer.FooterRows) ?
                                                         (dataGrid.VisualContainer.RowCount - dataGrid.VisualContainer.FooterRows) : coveredCell.Top,
                                                         coveredCell.Bottom);
                }
                else
                {
                    newCoveredCell = coveredCell;
                }

                dataGrid.CoveredCells.Add(newCoveredCell);

                this.UpdateMappedRowIndex(dr, dr.RowIndex);

                dataGrid.RowGenerator.Items.ForEach(row =>
                {
                    if (newCoveredCell != null && row.RowIndex < newCoveredCell.Top && row.RowIndex >= coveredCell.Top)
                    {
                        dataGrid.MergedCellManager.ResetCoveredRows(row);
                    }
                }
                                                    );
            }

            // Reset the covered cell range by right for frozen columns
            if (dataGrid.FrozenColumnCount > 0 && dc.ColumnIndex < dataGrid.VisualContainer.FrozenColumns)
            {
                CoveredCellInfo newCoveredCell = null;
                dataGrid.CoveredCells.Remove(coveredCell);
                if (coveredCell.Left < dataGrid.VisualContainer.FrozenColumns && coveredCell.Right >= dataGrid.VisualContainer.FrozenColumns)
                {
                    newCoveredCell = new CoveredCellInfo(coveredCell.Left,
                                                         coveredCell.Right < dataGrid.VisualContainer.FrozenColumns ? coveredCell.Right : dataGrid.VisualContainer.FrozenColumns - 1,
                                                         coveredCell.Top,
                                                         coveredCell.Bottom);
                }
                else
                {
                    newCoveredCell = coveredCell;
                }

                dataGrid.CoveredCells.Add(newCoveredCell);

                this.UpdateMappedRowIndex(dr, dr.RowIndex);

                dataGrid.RowGenerator.Items.ForEach(row =>
                {
                    if (newCoveredCell != null && row.RowIndex >= coveredCell.Top && row.RowIndex <= coveredCell.Bottom)
                    {
                        row.VisibleColumns.ForEach(column =>
                        {
                            if (column.ColumnIndex > newCoveredCell.Right && column.ColumnIndex <= coveredCell.Right)
                            {
                                column.isSpannedColumn  = false;
                                column.ColumnVisibility = Visibility.Visible;
                            }
                        });
                    }
                }
                                                    );
            }
            // Reset the covered cell range by left for frozen columns
            else if (dataGrid.FooterColumnCount > 0 && coveredCell.Right >= (dataGrid.VisualContainer.ColumnCount - dataGrid.VisualContainer.FooterColumns) && coveredCell.Right < dataGrid.VisualContainer.ColumnCount)
            {
                CoveredCellInfo newCoveredCell = null;
                dataGrid.CoveredCells.Remove(coveredCell);
                if ((dataGrid.VisualContainer.ColumnCount - dataGrid.VisualContainer.FooterColumns) >= coveredCell.Left && coveredCell.Right <= dataGrid.VisualContainer.ColumnCount)
                {
                    newCoveredCell = new CoveredCellInfo(coveredCell.Left,
                                                         coveredCell.Right < (dataGrid.VisualContainer.ColumnCount - dataGrid.VisualContainer.FooterColumns) ?
                                                         coveredCell.Right : dataGrid.VisualContainer.ColumnCount - dataGrid.VisualContainer.FooterColumns,
                                                         coveredCell.Top, coveredCell.Bottom);
                }
                else
                {
                    newCoveredCell = coveredCell;
                }

                dataGrid.CoveredCells.Add(newCoveredCell);

                this.UpdateMappedRowIndex(dr, dr.RowIndex);

                dataGrid.RowGenerator.Items.ForEach(row =>
                {
                    if (newCoveredCell != null && row.RowIndex >= coveredCell.Top && row.RowIndex <= coveredCell.Bottom)
                    {
                        row.VisibleColumns.ForEach(column =>
                        {
                            if (column.ColumnIndex > newCoveredCell.Right && column.ColumnIndex <= coveredCell.Right)
                            {
                                column.isSpannedColumn  = false;
                                column.ColumnVisibility = Visibility.Visible;
                            }
                        });
                    }
                }
                                                    );
            }
        }