Пример #1
0
        internal override void CreateOrUpdateDetailsViewDataRow(IEnumerable <DataRowBase> rows, int rowIndex, RecordEntry record, ViewDefinition detailsView, int detailsViewIndex, IEnumerable itemsSource)
        {
            // In grouping, 2 detailsview data row may have same CatchedRowIndex.So we need to check NotifyListener ClonedDataGrid. Then only it will return proper details view data row in case of multiple details view
            var dr = rows.OfType <DetailsViewDataRow>().FirstOrDefault(r => r.CatchedRowIndex == rowIndex && ((detailsView is GridViewDefinition) ? (detailsView as GridViewDefinition).NotifyListener.ClonedDataGrid.Contains((r as DetailsViewDataRow).DetailsViewDataGrid) : true));

            if (dr != null)
            {
                InitializeDetailsViewDataRow(rowIndex, record, dr, detailsViewIndex, detailsView, itemsSource);
                // We will update the changes immediately in all DetailsViewDataGrids using ClonedDataGrid.So below code is commented
                //EnsureProperties(dr.DetailsViewDataGrid);
                return;
            }

            if (detailsView is GridViewDefinition)
            {
                var gridViewDefinition = detailsView as GridViewDefinition;
                if (gridViewDefinition.NotifyListener != null)
                {
                    //Added the condition check CurrentItem of the DetailsViewDataGrid to preserve from reuse. If we reuse the currentcell maintained grid we cant get the grid after scrolling.
                    dr = rows.OfType <DetailsViewDataRow>().FirstOrDefault(r => !r.IsEnsured && r.DetailsViewDataGrid != this.DataGrid.SelectedDetailsViewGrid && r.DetailsViewDataGrid.SelectionController.CurrentCellManager.CurrentCell == null && gridViewDefinition.NotifyListener.ClonedDataGrid.Contains(r.DetailsViewDataGrid));
                    if (dr != null)
                    {
                        int repeatValueCount;
                        var isHidden             = this.DataGrid.VisualContainer.RowHeights.GetHidden(rowIndex, out repeatValueCount);
                        LineSizeCollection lines = null;
                        if (!isHidden)
                        {
                            lines = this.DataGrid.VisualContainer.RowHeights.GetNestedLines(rowIndex) as LineSizeCollection;
                        }
                        // While updating rowHeightsProvider, need to unwire the events. It will be hooked it InitialRefresh method
                        dr.DetailsViewDataGrid.GridColumnSizer.UnwireEvents();
                        dr.DetailsViewDataGrid.VisualContainer.UpdateRowInfo(lines, dr.DetailsViewDataGrid.RowHeight);
                        InitializeDetailsViewDataRow(rowIndex, record, dr, detailsViewIndex, detailsView, itemsSource);
                        // We will update the changes immediately in all DetailsViewDataGrids using ClonedDataGrid.So below code is commented
                        //EnsureProperties(dr.DetailsViewDataGrid);
                        return;
                    }
                }
            }
            dr = CreateDetailsViewDataRow(rowIndex, record, itemsSource);
            var detailsViewDataGrid = dr.DetailsViewDataGrid;

            // We will update the changes immediately in all DetailsViewDataGrids using ClonedDataGrid.So below code is commented
            //if (detailsViewDataGrid != null && detailsViewDataGrid.AutoGenerateColumns && detailsViewDataGrid.AutoGenerateColumnsMode == AutoGenerateColumnsMode.ResetAll)
            //    EnsureProperties(detailsViewDataGrid);
            this.DataGrid.RowGenerator.Items.Add(dr);
        }
Пример #2
0
        internal override void InitializeDetailsViewRow(int rowIndex, RecordEntry record, DetailsViewDataRow detailsViewDataRow, int detailsViewIndex, ViewDefinition detailsView, IEnumerable itemsSource)
        {
            if (detailsView is GridViewDefinition)
            {
                var gridViewDefinition = detailsView as GridViewDefinition;
                if (gridViewDefinition.NotifyListener == null)
                {
                    gridViewDefinition.NotifyListener = new DetailsViewNotifyListener(gridViewDefinition.DataGrid, this.DataGrid);
                }
                int repeatValueCount;
                var isHidden = this.DataGrid.VisualContainer.RowHeights.GetHidden(rowIndex, out repeatValueCount);
                if (detailsViewDataRow.DetailsViewDataGrid == null)
                {
                    var grid = gridViewDefinition.NotifyListener.CopyPropertiesFromSourceDataGrid(gridViewDefinition.DataGrid);
                    (grid.NotifyListener as DetailsViewNotifyListener)._parentDataGrid = this.DataGrid;
                    // Apply style for DetailsViewDataGrid
                    if (this.DataGrid.ReadLocalValue(SfDataGrid.DetailsViewDataGridStyleProperty) != DependencyProperty.UnsetValue)
                    {
                        grid.Style = this.DataGrid.DetailsViewDataGridStyle;
                    }
                    //grid.VisualContainer.ScrollOwner = this.DataGrid.VisualContainer.ScrollOwner;
                    detailsViewDataRow.DetailsViewDataGrid = grid;
                }
                (detailsViewDataRow.DetailsViewDataGrid.NotifyListener as DetailsViewNotifyListener)._parentDataGrid = this.DataGrid;

                bool needtoinvalidatelinecollection = false;

                if (record.ChildViews != null && record.ChildViews.ContainsKey(gridViewDefinition.RelationalColumn) && record.ChildViews[gridViewDefinition.RelationalColumn].View != null)
                {
                    var recordView = record.ChildViews[gridViewDefinition.RelationalColumn].View;
                    if (detailsViewDataRow.DetailsViewDataGrid.View == recordView)
                    {
                        // If we assign new RowHeights in CreateOrUpdateDetailsViewDataRow, need to update Row and Column count here
                        if (detailsViewDataRow.DetailsViewDataGrid.VisualContainer.RowHeights.TotalExtent == 0)
                        {
                            detailsViewDataRow.DetailsViewDataGrid.RefreshHeaderLineCount();
                            detailsViewDataRow.DetailsViewDataGrid.UpdateRowAndColumnCount(false);
                            detailsViewDataRow.DetailsViewDataGrid.RowGenerator.Items.ForEach(item => item.RowIndex = -1);
                        }
                        // Need to update DataGrid in CollectionView
                        if (detailsViewDataRow.DetailsViewDataGrid.View is IGridViewNotifier)
                        {
                            (detailsViewDataRow.DetailsViewDataGrid.View as IGridViewNotifier).AttachGridView(detailsViewDataRow.DetailsViewDataGrid);
                        }
                    }
                    if (detailsViewDataRow.DetailsViewDataGrid.View != recordView)
                    {
                        detailsViewDataRow.RowData = recordView.SourceCollection;
                        // Remove detailsview grid from ClonedDataGrid list
                        UpdateClonedDataGrid(detailsViewDataRow);

                        // WPF-22862 - in some cases, recordView is view of some DetailsViewDataGrid. But it will not be taken for reuse.
                        // So need to unwire events from that DetailsViewDataGrid
                        if (recordView is IGridViewNotifier)
                        {
                            var grid = (recordView as IGridViewNotifier).GetDataGrid();
                            if (grid is SfDataGrid)
                            {
                                var dataGrid = grid as SfDataGrid;
                                dataGrid.GridModel.UnWireEvents(false);
                                (recordView as IGridViewNotifier).DetachGridView();
                                dataGrid.suspendItemsSourceChanged = true;
                                dataGrid.ItemsSource = null;
                                dataGrid.View        = null;
                                dataGrid.RefreshHeaderLineCount();
                                dataGrid.UpdateRowAndColumnCount(false);
                                dataGrid.suspendItemsSourceChanged = false;
                            }
                        }

                        // While reusing view, need to clear previous view properties. Because properties will be updated in DetailsViewDataGrid only
                        DetailsViewHelper.ClearViewProperties(recordView);
                        detailsViewDataRow.DetailsViewDataGrid.ItemsSource = recordView;
                    }

                    // Expand the records in DetailsViewDataGrid based on IsNestedLevelExpanded and ExpandedLevel
                    if (record.ChildViews[gridViewDefinition.RelationalColumn].IsNestedLevelExpanded || record.ChildViews[gridViewDefinition.RelationalColumn].ExpandedLevel > 1)
                    {
                        detailsViewDataRow.DetailsViewDataGrid.DetailsViewManager.ExpandAllDetailsView(record.ChildViews[gridViewDefinition.RelationalColumn].IsNestedLevelExpanded ? -1 : record.ChildViews[gridViewDefinition.RelationalColumn].ExpandedLevel - 1);
                    }
                    else
                    {
                        // If DetailsViewDataGrid's record is already expanded, need to collapse it
                        if (record.ChildViews[gridViewDefinition.RelationalColumn].ExpandedLevel != -1)
                        {
                            detailsViewDataRow.DetailsViewDataGrid.CollapseAllDetailsView();
                        }
                    }
                    if (detailsViewDataRow.DetailsViewDataGrid.View != null)
                    {
                        foreach (var childrecord in detailsViewDataRow.DetailsViewDataGrid.View.Records.Where(r => r.IsExpanded))
                        {
                            for (int i = 1; i <= detailsViewDataRow.DetailsViewDataGrid.DetailsViewDefinition.Count; i++)
                            {
                                var childRowIndex = detailsViewDataRow.DetailsViewDataGrid.ResolveToRowIndex(childrecord);
                                int valueCount;
                                if (detailsViewDataRow.DetailsViewDataGrid.VisualContainer.RowHeights.GetHidden(childRowIndex + i, out valueCount))
                                {
                                    detailsViewDataRow.DetailsViewDataGrid.VisualContainer.RowHeights.SetHidden(childRowIndex + i, childRowIndex + i, false);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (itemsSource == null)
                    {
                        itemsSource = GetChildSource(record.Data, gridViewDefinition.RelationalColumn);
                    }

                    // If itemssource is same, we need to set itemssource as null.
                    if (detailsViewDataRow.DetailsViewDataGrid.ItemsSource == itemsSource)
                    {
                        // Remove detailsview grid from ClonedDataGrid list
                        UpdateClonedDataGrid(detailsViewDataRow);
                        detailsViewDataRow.DetailsViewDataGrid.ItemsSource = null;
                        // if itemsSource and DetailsViewDataGrid's itemssource is null, need to update RowCount here(since itemssourcechanged callback will not be called)
                        if (itemsSource == null)
                        {
                            detailsViewDataRow.DetailsViewDataGrid.RefreshHeaderLineCount();
                            detailsViewDataRow.DetailsViewDataGrid.UpdateRowAndColumnCount(false);
                        }
                    }
                    else
                    {
                        needtoinvalidatelinecollection = true;
                    }
                    detailsViewDataRow.RowData = itemsSource;
                    // Remove detailsview grid from ClonedDataGrid list
                    UpdateClonedDataGrid(detailsViewDataRow);
                    detailsViewDataRow.DetailsViewDataGrid.ItemsSource = detailsViewDataRow.RowData;

                    // Expand the records in DetailsViewDataGrid based on IsNestedLevelExpanded and ExpandedLevel
                    if (!isHidden && ((record.ChildViews != null && record.ChildViews.ContainsKey(gridViewDefinition.RelationalColumn) && record.ChildViews[gridViewDefinition.RelationalColumn].ExpandedLevel > 1) || (record.ChildViews != null && record.ChildViews.ContainsKey(gridViewDefinition.RelationalColumn) && record.ChildViews[gridViewDefinition.RelationalColumn].IsNestedLevelExpanded)))
                    {
                        detailsViewDataRow.DetailsViewDataGrid.DetailsViewManager.ExpandAllDetailsView(record.ChildViews[gridViewDefinition.RelationalColumn].IsNestedLevelExpanded ? -1 : record.ChildViews[gridViewDefinition.RelationalColumn].ExpandedLevel - 1);
                    }
                    else
                    {
                        // If DetailsViewDataGrid's record is already expanded, need to collapse it
                        if (record.ChildViews != null && record.ChildViews.ContainsKey(gridViewDefinition.RelationalColumn) && record.ChildViews[gridViewDefinition.RelationalColumn].ExpandedLevel != -1)
                        {
                            detailsViewDataRow.DetailsViewDataGrid.CollapseAllDetailsView();
                        }
                    }
                    var isNestedExpanded = false;
                    var level            = 0;
                    if (record.ChildViews.ContainsKey(gridViewDefinition.RelationalColumn))
                    {
                        isNestedExpanded = record.ChildViews[gridViewDefinition.RelationalColumn].IsNestedLevelExpanded;
                        level            = record.ChildViews[gridViewDefinition.RelationalColumn].ExpandedLevel;
                    }
                    record.ChildViews.Remove(gridViewDefinition.RelationalColumn);
                    record.PopulateChildView(detailsViewDataRow.DetailsViewDataGrid.View, detailsViewIndex, gridViewDefinition.RelationalColumn, isNestedExpanded);
                    record.ChildViews[gridViewDefinition.RelationalColumn].ExpandedLevel = level;
                    ResetTopLevelGroupCache();
                }

                if (detailsViewDataRow.WholeRowElement != null)
                {
                    if (this.DataGrid.HideEmptyGridViewDefinition)
                    {
                        ApplyVisualState(rowIndex, record, detailsViewDataRow);
                    }
                    else
                    {
                        detailsViewDataRow.ApplyContentVisualState(detailsViewIndex ==
                                                                   this.DataGrid.DetailsViewDefinition.Count - 1
                                                                        ? "LastCell"
                                                                        : "NormalCell");
                    }
                }
                // Set PaddingDistance for DetailsViewDataGrid
                if (detailsViewDataRow.DetailsViewDataGrid.AllowDetailsViewPadding)
                {
                    var paddingDistance = detailsViewDataRow.DetailsViewDataGrid.DetailsViewPadding.Top + detailsViewDataRow.DetailsViewDataGrid.DetailsViewPadding.Bottom + 1;
                    if (detailsViewIndex == this.DataGrid.DetailsViewDefinition.Count - 1 || detailsViewDataRow.DetailsViewContentPresenter.CurrentVisualState == "LastCell")
                    {
                        paddingDistance += 1;
                    }
                    detailsViewDataRow.DetailsViewDataGrid.VisualContainer.RowHeights.PaddingDistance = paddingDistance;
                }

                this.DataGrid.VisualContainer.RowHeights.SetNestedLines(rowIndex, detailsViewDataRow.DetailsViewDataGrid.VisualContainer.RowHeights);

                if (detailsViewDataRow.DetailsViewDataGrid.View != null && detailsViewDataRow.DetailsViewDataGrid.Columns.Any(column => column.FilterPredicates.Any()))
                {
                    detailsViewDataRow.DetailsViewDataGrid.GridModel.ApplyFilter();
                    // WPF-18240 - While expanding the record fist time, detailsview data row will not be added to parent grid. So unable to invalidate nested lines in RefreshParentDataGrid method
                    // Below code is added to invalidate nested lines when filtering is applied
                    //var lineCollection = (this.DataGrid.VisualContainer.RowHeights as LineSizeCollection);
                    //if (lineCollection != null && lineCollection.Distances is DistanceRangeCounterCollection)
                    //    (lineCollection.Distances as DistanceRangeCounterCollection).InvalidateNestedEntry(rowIndex);
                    needtoinvalidatelinecollection = true;
                }
#if WPF
                if (detailsViewDataRow.DetailsViewDataGrid.SearchHelper.AllowFiltering)
                {
                    detailsViewDataRow.DetailsViewDataGrid.View.Filter = detailsViewDataRow.DetailsViewDataGrid.SearchHelper.FilterRecords;
                    detailsViewDataRow.DetailsViewDataGrid.View.RefreshFilter();
                    needtoinvalidatelinecollection = true;
                }
#endif
                if (needtoinvalidatelinecollection)
                {
                    var lineCollection = (this.DataGrid.VisualContainer.RowHeights as LineSizeCollection);
                    if (lineCollection != null && lineCollection.Distances is DistanceRangeCounterCollection)
                    {
                        (lineCollection.Distances as DistanceRangeCounterCollection).InvalidateNestedEntry(rowIndex);
                    }
                }
                detailsViewDataRow.DetailsViewDataGrid.DetailsViewManager.UpdateExtendedWidth();
                //(WPF - 37043) When Child grid's columnsizer is Star, Parent Grid's width need not to be adjusted.
                if (detailsViewDataRow.DetailsViewDataGrid.ColumnSizer != GridLengthUnitType.Star)
                {
                    AdjustParentsWidth(this.DataGrid, detailsViewDataRow.DetailsViewDataGrid, rowIndex);
                }
                // To refresh parent grid height in case of multi level nested grid and grouping
                DetailsViewHelper.RefreshParentDataGridRows(detailsViewDataRow.DetailsViewDataGrid);
            }
        }