Exemplo n.º 1
0
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            bool           allowGroupingModification = true;
            GroupByControl parentGBC = this.GetParentGroupByControl();

            if (parentGBC != null)
            {
                allowGroupingModification = parentGBC.IsGroupingModificationAllowed;
            }

            // We don't accept any ColumnManagerCell from Details
            DataGridContext context = DataGridControl.GetDataGridContext(draggedElement);

            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            bool isAlreadyGroupedBy = false;

            if (cell != null)
            {
                isAlreadyGroupedBy = GroupingHelper.IsAlreadyGroupedBy(cell);
                ColumnBase parentColumn = cell.ParentColumn;

                if ((parentColumn == null) || (!parentColumn.AllowGroup))
                {
                    return(false);
                }
            }

            DataGridContext sourceDetailContext = DataGridControl.GetDataGridContext(this);

            Debug.Assert(sourceDetailContext != null);
            DetailConfiguration sourceDetailConfig = (sourceDetailContext != null) ? sourceDetailContext.SourceDetailConfiguration : null;

            DataGridContext draggedDetailContext = DataGridControl.GetDataGridContext(draggedElement);

            Debug.Assert(draggedDetailContext != null);
            DetailConfiguration draggedDetailConfig = (draggedDetailContext != null) ? draggedDetailContext.SourceDetailConfiguration : null;


            bool canDrop = (sourceDetailConfig == draggedDetailConfig) &&
                           (allowGroupingModification) &&
                           ((draggedElement is ColumnManagerCell) || (draggedElement is GroupByItem)) &&
                           (draggedElement != this) &&
                           (isAlreadyGroupedBy == false);

            if (canDrop && (cell != null))
            {
                canDrop = GroupingHelper.ValidateMaxGroupDescriptions(draggedDetailContext);
            }

            return(canDrop);
        }
Exemplo n.º 2
0
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            bool isAlreadyGroupedBy = false;

            ColumnManagerCell cell = draggedElement as ColumnManagerCell;

            if (cell != null)
            {
                isAlreadyGroupedBy = GroupingHelper.IsAlreadyGroupedBy(cell);
                ColumnBase parentColumn = cell.ParentColumn;

                if ((parentColumn == null) || (!parentColumn.AllowGroup))
                {
                    return(false);
                }
            }

            DataGridContext sourceDetailContext = DataGridControl.GetDataGridContext(this);

            Debug.Assert(sourceDetailContext != null);
            DetailConfiguration sourceDetailConfig = (sourceDetailContext != null) ? sourceDetailContext.SourceDetailConfiguration : null;

            DataGridContext draggedDetailContext = DataGridControl.GetDataGridContext(draggedElement);

            Debug.Assert(draggedDetailContext != null);
            DetailConfiguration draggedDetailConfig = (draggedDetailContext != null) ? draggedDetailContext.SourceDetailConfiguration : null;


            bool canDrop = (sourceDetailConfig == draggedDetailConfig) &&
                           (sourceDetailContext != null) &&
                           (draggedDetailContext != null) &&
                           (sourceDetailContext.GroupLevelDescriptions == draggedDetailContext.GroupLevelDescriptions) &&
                           (this.IsGroupingModificationAllowed) &&
                           ((draggedElement is ColumnManagerCell) || (draggedElement is GroupByItem)) &&
                           (!isAlreadyGroupedBy);

            if (canDrop && (cell != null))
            {
                canDrop = GroupingHelper.ValidateMaxGroupDescriptions(draggedDetailContext);
            }

            return(canDrop);
        }
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            ColumnManagerCell       cell = null;
            HierarchicalGroupByItem hierarchicalGroupByItem = null;
            bool canDrop = this.AllowGroupingModification;

            if (canDrop)
            {
                cell = draggedElement as ColumnManagerCell;

                if (cell != null)
                {
                    ColumnBase parentColumn = cell.ParentColumn;

                    if ((parentColumn == null) || (!parentColumn.AllowGroup))
                    {
                        return(false);
                    }

                    // Check if already grouped using the cell's DataGridContext
                    canDrop = !GroupingHelper.IsAlreadyGroupedBy(cell);

                    if (canDrop)
                    {
                        // Get the HierarchicalGroupByControl for this HierarchicalGroupByControlNode
                        HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(this);

                        if (parentGBC == null)
                        {
                            throw new DataGridInternalException("The hierarchical group-by control node must be rooted by a HierarchicalGroupByControl.");
                        }

                        DataGridContext parentGBCDataGridContext = DataGridControl.GetDataGridContext(parentGBC);

                        Debug.Assert(parentGBCDataGridContext != null);

                        if (parentGBCDataGridContext.Items != null)
                        {
                            canDrop = parentGBCDataGridContext.Items.CanGroup;
                        }

                        if (canDrop)
                        {
                            canDrop = GroupingHelper.IsColumnManagerCellInDataGridContext(parentGBCDataGridContext, cell);

                            if (canDrop == true)
                            {
                                canDrop = GroupingHelper.ValidateMaxGroupDescriptions(DataGridControl.GetDataGridContext(draggedElement));
                            }
                        }
                    }
                }
                else
                {
                    hierarchicalGroupByItem = draggedElement as HierarchicalGroupByItem;

                    if (hierarchicalGroupByItem == null)
                    {
                        canDrop = false;
                    }

                    if (canDrop)
                    {
                        HierarchicalGroupByControl parentGBC = GroupingHelper.GetHierarchicalGroupByControl(this);

                        if (parentGBC == null)
                        {
                            throw new DataGridInternalException("The hierarchical group-by control node must be rooted by a HierarchicalGroupByControl.");
                        }

                        // Try to get the HierarchicalGroupByControlNode in which this HierarchicalGroupByItem can be added using the parent HierarchicalGroupByControl => null it can't
                        HierarchicalGroupByControlNode draggedHierarchicalGroupByControlNode = parentGBC.GetHierarchicalGroupByControlNodeFromHierarchicalGroupByItem(hierarchicalGroupByItem);

                        if (draggedHierarchicalGroupByControlNode == null)
                        {
                            canDrop = false;
                        }
                    }
                }
            }

            bool returnedValue = ((cell != null) || (hierarchicalGroupByItem != null)) &&// ColumnManagerCell or HierarchicalGroupByItem
                                 (canDrop);


            return(returnedValue);
        }
        bool IDropTarget.CanDropElement(UIElement draggedElement)
        {
            bool canDrop = this.AllowGroupingModification;

            ColumnManagerCell       cell = null;
            HierarchicalGroupByItem hierarchicalGroupByItem = null;

            if (canDrop)
            {
                cell = draggedElement as ColumnManagerCell;

                if (cell != null)
                {
                    ColumnBase parentColumn = cell.ParentColumn;

                    if ((parentColumn == null) || (!parentColumn.AllowGroup))
                    {
                        return(false);
                    }

                    // Check if already grouped using the cell's DataGridContext
                    canDrop = !GroupingHelper.IsAlreadyGroupedBy(cell);

                    if (canDrop)
                    {
                        DataGridContext thisDataGridContext = DataGridControl.GetDataGridContext(this);

                        if (thisDataGridContext.Items != null)
                        {
                            canDrop = thisDataGridContext.Items.CanGroup;
                        }

                        if (canDrop)
                        {
                            canDrop = GroupingHelper.IsColumnManagerCellInDataGridContext(thisDataGridContext, cell);

                            if (canDrop == true)
                            {
                                canDrop = GroupingHelper.ValidateMaxGroupDescriptions(DataGridControl.GetDataGridContext(draggedElement));
                            }
                        }
                    }
                }
                else
                {
                    hierarchicalGroupByItem = draggedElement as HierarchicalGroupByItem;

                    if (hierarchicalGroupByItem == null)
                    {
                        canDrop = false;
                    }

                    if (canDrop)
                    {
                        // Try to get the HierarchicalGroupByControlNode in which this HierarchicalGroupByItem can be added using the parent HierarchicalGroupByControl => null it can't
                        HierarchicalGroupByControlNode draggedHierarchicalGroupByControlNode = this.GetHierarchicalGroupByControlNodeFromHierarchicalGroupByItem(hierarchicalGroupByItem);

                        if (draggedHierarchicalGroupByControlNode == null)
                        {
                            canDrop = false;
                        }
                    }
                }
            }

            bool returnedValue = ((cell != null) || (hierarchicalGroupByItem != null)) && // ColumnManagerCell or HierarchicalGroupByItem
                                 (canDrop);


            return(returnedValue);
        }