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(); }
internal override void EnsureColumns(VisibleLinesCollection visibleColumnLines) { // Initially all the columns will be IsEnsured false. we need to create the column to be view and that will be ensuered. this.VisibleColumns.ForEach(column => column.IsEnsured = false); var needToUpdateCurrentCell = this.TreeGrid.SelectionMode != GridSelectionMode.None && this.RowIndex != -1 && this.TreeGrid.NavigationMode == NavigationMode.Cell && !this.TreeGrid.SelectionController.CurrentCellManager.HasCurrentCell && this.RowIndex == this.TreeGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex.RowIndex; //StartBodyColumnIndex - Which will make sure the actual column index. var StartBodyColumnIndex = (visibleColumnLines.firstBodyVisibleIndex < visibleColumnLines.Count) ? visibleColumnLines[visibleColumnLines.firstBodyVisibleIndex].LineIndex : visibleColumnLines[visibleColumnLines.LastBodyVisibleIndex].LineIndex; for (int i = 0; i < 2; i++) { int StartColumnIndex = 0; int EndColumnIndex = 0; if (i == 0) { if (visibleColumnLines.FirstBodyVisibleIndex <= 0) { continue; } StartColumnIndex = 0; EndColumnIndex = visibleColumnLines[visibleColumnLines.FirstBodyVisibleIndex - 1].LineIndex; } // Below will make sure the start and end column index of row. which includes only data column. 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; } for (int index = StartColumnIndex; index <= EndColumnIndex; index++) { if (visibleColumnLines.All(row => row.LineIndex != index)) { continue; } if (TreeGrid.showRowHeader && index == 0) { // Reuse the row header column by checking ColumnType instead of ColumnIndex (since we reset column index while removing row header column if ShowRowHeader is False). var rhc = this.VisibleColumns.FirstOrDefault(column => column.ColumnType == TreeColumnType.RowHeader); if (rhc != null) { if (rhc.ColumnVisibility == Visibility.Collapsed) { rhc.ColumnVisibility = Visibility.Visible; } rhc.IsEnsured = true; // To reuse the column, need to set the column index here. rhc.ColumnIndex = 0; } else { CreateRowHeaderColumn(index); } continue; } if (this.VisibleColumns.All(column => column.ColumnIndex != index || this.isDirty)) { var hasExpanderColumn = this.VisibleColumns.Any(c => c.ColumnType == TreeColumnType.ExpanderColumn); var isExpanderColumn = IsExpanderColumn(index); // ColumnIndex needs to be checked with StartBodyColumnIndex and EndColumnIndex - Due to avoid reusing freezed columns from header and footer. TreeDataColumnBase dataColumn; if (hasExpanderColumn && isExpanderColumn) { dataColumn = this.VisibleColumns.FirstOrDefault( column => ((column.ColumnIndex <StartBodyColumnIndex || column.ColumnIndex> EndColumnIndex || this.isDirty) && !column.IsEnsured && !column.IsEditing && (!column.IsCurrentCell || this.isDirty) && column.ColumnType == TreeColumnType.ExpanderColumn)); } else { dataColumn = this.VisibleColumns.FirstOrDefault( column => ((column.ColumnIndex <StartBodyColumnIndex || column.ColumnIndex> EndColumnIndex || this.isDirty) && !column.IsEnsured && column.ColumnType != TreeColumnType.RowHeader && !column.IsEditing && (!column.IsCurrentCell || this.isDirty) && (column.ColumnType != TreeColumnType.ExpanderColumn || (column.ColumnType == TreeColumnType.ExpanderColumn && isExpanderColumn)))); } if (dataColumn != null && (!isExpanderColumn || dataColumn.ColumnType == TreeColumnType.ExpanderColumn)) { // which will reuse the column element fully, or load its element with different one. UpdateColumn(dataColumn, index); } } var dc = this.VisibleColumns.FirstOrDefault(column => column.ColumnIndex == index); if (dc != null) { if (dc.ColumnVisibility == Visibility.Collapsed) { dc.ColumnVisibility = Visibility.Visible; dc.UpdateCellStyle(); if (dc.Renderer != null && (dc.Renderer.HasCurrentCellState && (dc.IsEditing || dc.TreeGridColumn.CanFocus()))) { dc.Renderer.SetFocus(true); } } if (needToUpdateCurrentCell) { this.UpdateCurrentCellSelection(dc); } dc.IsEnsured = true; } else { if (index >= this.TreeGrid.TreeGridPanel.ColumnCount) { continue; } var datacolumn = CreateColumn(index); if (needToUpdateCurrentCell) { this.UpdateCurrentCellSelection(datacolumn); } datacolumn.IsEnsured = true; this.VisibleColumns.Add(datacolumn); } } } this.VisibleColumns.ForEach(column => { if (!column.IsEnsured) { CollapseColumn(column); } }); this.isDirty = false; Panel panel = this.RowElement.ItemsPanel; if (panel != null && this.TreeGrid.IsLoaded) { panel.InvalidateMeasure(); } }