private void UpdateDataRow(IEnumerable <TreeDataRowBase> rows, int rowIndex, RowRegion region) { if (rows.Any(row => row.RowType == TreeRowType.DefaultRow)) { var dr = rows.FirstOrDefault(r => r.RowType == TreeRowType.DefaultRow); var node = Owner.GetNodeAtRowIndex(rowIndex); if (node != null) { dr.Node = node; dr.Level = node.Level; dr.HasChildNodes = node.HasVisibleChildNodes; dr.RowData = node.Item; } dr.RowIndex = rowIndex; if (dr.RowVisibility == Visibility.Collapsed) { dr.RowVisibility = Visibility.Visible; } this.CheckForSelection(dr); if (this.Owner.Columns.Any(col => col.GridValidationMode != GridValidationMode.None)) { this.Owner.ValidationHelper.ValidateColumns(dr); } dr.ApplyRowHeaderVisualState(); dr.RowElement.UpdateIndentMargin(); } else { var dr = CreateDataRow(rowIndex, this.TreePanel.ScrollColumns.GetVisibleLines()); this.Items.Add(dr); } }
private void UpdateRow(IEnumerable <TreeDataRowBase> rows, int rowIndex, RowRegion region) { if (rowIndex == Owner.GetHeaderIndex()) { var headerRow = rows.FirstOrDefault(r => r.RowType == TreeRowType.HeaderRow); if (headerRow != null) { headerRow.RowIndex = rowIndex; headerRow.TreeGrid = this.Owner; if (headerRow.RowVisibility == Visibility.Collapsed) { headerRow.RowVisibility = Visibility.Visible; } } else { headerRow = CreateHeaderRow(rowIndex, TreePanel.ScrollColumns.GetVisibleLines()); this.Items.Add(headerRow); } } else { UpdateDataRow(rows, rowIndex, region); } }
/// <summary> /// Updates the region of rows for the specified start and end index. /// </summary> /// <param name="start"> /// The start index to update. /// </param> /// <param name="end"> /// The end index to update. /// </param> /// <param name="region"> /// The region that is to be updated. /// </param> public void UpdateRegion(int start, int end, RowRegion region) { Range range = null; if (region == RowRegion.Header) { range = Header; } else if (region == RowRegion.Body) { range = Body; } else { range = Footer; } range.start = start; range.end = end; }
/// <summary> /// Determines whether the particular index is contained in specified region. /// </summary> /// <param name="index"> /// The corresponding index to check whether it is contained in specified region. /// </param> /// <param name="region"> /// The corresponding region. /// </param> /// <returns> /// Returns <b>true</b> if the index is present in specified region; otherwise, <b>false</b>. /// </returns> public bool Contains(int index, RowRegion region) { Range range = null; if (region == RowRegion.Header) { range = Header; } else if (region == RowRegion.Body) { range = Body; } else { range = Footer; } if (range.IsEmpty) { if (DirectoryRows.Contains(index)) { DirectoryRows.Remove(index); } return(false); } if (index >= range.start && index <= range.end) { if (DirectoryRows.Contains(index)) { DirectoryRows.Remove(index); return(false); } return(true); } return(false); }
/// <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; } }); } } ); } }