Exemplo n.º 1
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;
                            }
                        });
                    }
                }
                                                    );
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines whether the specified row index is associated with DetailsViewDataGrid row.
        /// </summary>
        /// <param name="dataGrid">
        /// The SfDataGrid.
        /// </param>
        /// <param name="rowIdx">
        /// The corresponding row index to determine whether the row index in Details View DataGrid.
        /// </param>
        /// <returns>
        /// Returns <b>true</b> if the specified row index is  Details View index; otherwise, <b>false</b>.
        /// </returns>
        public static bool IsInDetailsViewIndex(this SfDataGrid dataGrid, int rowIdx)
        {
            if (!dataGrid.DetailsViewManager.HasDetailsView || rowIdx < 0)
            {
                return(false);
            }

            if (dataGrid.IsAddNewIndex(rowIdx) || dataGrid.IsFilterRowIndex(rowIdx) || dataGrid.IsUnBoundRow(rowIdx) || dataGrid.IsTableSummaryIndex(rowIdx))
            {
                return(false);
            }

            var startIdx = dataGrid.ResolveStartIndexBasedOnPosition();
            var counter0 = Math.Max((rowIdx - startIdx), 0);

            if (dataGrid.GridModel.HasGroup)
            {
                var displayEl = dataGrid.View.TopLevelGroup.DisplayElements[counter0];
                return(displayEl is NestedRecordEntry);
            }

            return((counter0 % (dataGrid.DetailsViewDefinition.Count + 1)) != 0);
        }