src/Misc/EFTools/DesignXmlCore/VirtualTreeGrid/UI/VirtualTreeControl.cs
/// <summary>
///     Package a drag object to use with DoDragDrop or Copy/Paste operations. Use the passed in location
///     for a single select tree, and the current selection state for a multiselect tree. Derived
///     classes can override this function to add extra information to the returned drag data. Any override
///     should first defer to the base implementation.
/// </summary>
/// <param name="row">Target row in the tree</param>
/// <param name="nativeColumn">The native column</param>
/// <param name="dragReason">The reason for retrieving the drop object</param>
/// <returns>A populated drag structure. IsEmpty may be true.</returns>
Package a drag object to use with DoDragDrop or Copy/Paste operations. Use the passed in location
for a single select tree, and the current selection state for a multiselect tree. Derived
classes can override this function to add extra information to the returned drag data. Any override
should first defer to the base implementation.
Package a drag object to use with DoDragDrop or Copy / Paste operations . Use the passed in location for a single select tree and the current selection state for a multiselect tree . Derived classes can override this function to add extra information to the returned drag data . Any override should first defer to the base implementation .
protected virtual VirtualTreeStartDragData PopulateDragData(int row, int nativeColumn, DragReason dragReason)
        {
            ClearDragSources();
            if (GetStyleFlag(VTCStyleFlags.MultiSelect))
            {
                var iter = CreateSelectedItemEnumerator();
                if (iter != null)
                {
                    var finished = false;
                    try
                    {
                        List<VirtualTreeStartDragData> sourceData = null;
                        var firstDragData = new VirtualTreeStartDragData();
                        var intersectEffects = GetStateFlag(VTCStateFlags.CombineDragEffectsWithAnd);
                        var allowedEffects = DragDropEffects.None;
                        var totalCount = 0;
                        while (iter.MoveNext())
                        {
                            var dragData = iter.Branch.OnStartDrag(this, iter.RowInBranch, iter.ColumnInBranch, dragReason);
                            if (dragReason == DragReason.CanCut
                                || dragReason == DragReason.CanCopy)
                            {
                                if (dragData == VirtualTreeStartDragData.AllowCutCopy)
                                {
                                    firstDragData = dragData;
                                    totalCount = 1;
                                }
                                else
                                {
                                    finished = true;
                                    return VirtualTreeStartDragData.Empty;
                                }
                            }
                            else if (!dragData.IsEmpty)
                            {
                                if (totalCount == 0)
                                {
                                    mySingleDragSource = new DragSourceOwner(iter.Branch, iter.RowInBranch, iter.ColumnInBranch);
                                    firstDragData = dragData;
                                    allowedEffects = dragData.AllowedEffects;
                                    ++totalCount;
                                }
                                else
                                {
                                    if (totalCount == 1)
                                    {
                                        sourceData = new List<VirtualTreeStartDragData>();
                                        sourceData.Add(firstDragData);
                                        if (myDragSources == null)
                                        {
                                            myDragSources = new List<DragSourceOwner>();
                                        }
                                        myDragSources.Add(mySingleDragSource);
                                        mySingleDragSource.Clear();
                                    }
                                    myDragSources.Add(new DragSourceOwner(iter.Branch, iter.RowInBranch, iter.ColumnInBranch));
                                    if (intersectEffects)
                                    {
                                        allowedEffects &= dragData.AllowedEffects;
                                        if (allowedEffects == 0)
                                        {
                                            return VirtualTreeStartDragData.Empty;
                                        }
                                    }
                                    else
                                    {
                                        allowedEffects |= dragData.AllowedEffects;
                                    }
                                    sourceData.Add(dragData);
                                    ++totalCount;
                                }
                            }
                        }
                        finished = true;
                        if (totalCount == 1)
                        {
                            return firstDragData;
                        }
                        else if (totalCount > 1)
                        {
                            return new VirtualTreeStartDragData(sourceData.ToArray(), allowedEffects);
                        }
                    }
                    finally
                    {
                        if (!finished)
                        {
                            ForceCancelDataSources();
                        }
                    }
                }
            }
            else
            {
                var info = myTree.GetItemInfo(row, nativeColumn, false);
                var dragData = info.Branch.OnStartDrag(this, info.Row, info.Column, dragReason);
                if (!dragData.IsEmpty)
                {
                    mySingleDragSource = new DragSourceOwner(info.Branch, info.Row, info.Column);
                    return dragData;
                }
            }
            return VirtualTreeStartDragData.Empty;
        }
protected virtual VirtualTreeStartDragData PopulateDragData ( int row , int nativeColumn , DragReason dragReason ) { ClearDragSources ( ) ; if ( GetStyleFlag ( VTCStyleFlags . MultiSelect ) ) { var iter = CreateSelectedItemEnumerator ( ) ; if ( iter != null ) { var finished = false ; try { List < VirtualTreeStartDragData > sourceData = null ; var firstDragData = new VirtualTreeStartDragData ( ) ; var intersectEffects = GetStateFlag ( VTCStateFlags . CombineDragEffectsWithAnd ) ; var allowedEffects = DragDropEffects . None ; var totalCount = 0 ; while ( iter . MoveNext ( ) ) { var dragData = iter . Branch . OnStartDrag ( this , iter . RowInBranch , iter . ColumnInBranch , dragReason ) ; if ( dragReason == DragReason . CanCut || dragReason == DragReason . CanCopy ) { if ( dragData == VirtualTreeStartDragData . AllowCutCopy ) { firstDragData = dragData ; totalCount = 1 ; } else { finished = true ; return VirtualTreeStartDragData . Empty ; } } else if ( ! dragData . IsEmpty ) { if ( totalCount == 0 ) { mySingleDragSource = new DragSourceOwner ( iter . Branch , iter . RowInBranch , iter . ColumnInBranch ) ; firstDragData = dragData ; allowedEffects = dragData . AllowedEffects ; ++ totalCount ; } else { if ( totalCount == 1 ) { sourceData = new List < VirtualTreeStartDragData > ( ) ; sourceData . Add ( firstDragData ) ; if ( myDragSources == null ) { myDragSources = new List < DragSourceOwner > ( ) ; } myDragSources . Add ( mySingleDragSource ) ; mySingleDragSource . Clear ( ) ; } myDragSources . Add ( new DragSourceOwner ( iter . Branch , iter . RowInBranch , iter . ColumnInBranch ) ) ; if ( intersectEffects ) { allowedEffects &= dragData . AllowedEffects ; if ( allowedEffects == 0 ) { return VirtualTreeStartDragData . Empty ; } } else { allowedEffects |= dragData . AllowedEffects ; } sourceData . Add ( dragData ) ; ++ totalCount ; } } } finished = true ; if ( totalCount == 1 ) { return firstDragData ; } else if ( totalCount > 1 ) { return new VirtualTreeStartDragData ( sourceData . ToArray ( ) , allowedEffects ) ; } } finally { if ( ! finished ) { ForceCancelDataSources ( ) ; } } } } else { var info = myTree . GetItemInfo ( row , nativeColumn , false ) ; var dragData = info . Branch . OnStartDrag ( this , info . Row , info . Column , dragReason ) ; if ( ! dragData . IsEmpty ) { mySingleDragSource = new DragSourceOwner ( info . Branch , info . Row , info . Column ) ; return dragData ; } } return VirtualTreeStartDragData . Empty ; }
Package a drag object to use with DoDragDrop or Copy/Paste operations.
Package a drag object to use with DoDragDrop or Copy / Paste operations .
// special handling for cut/copy queries. // bail out, operation is not supported // Store the first one without using the lists, we return it directly in this case // We're moving from a single item to multiple items. // Move our single drag data and source information into // lists. // Add source owners before the potential cancel coming from intersectAffects // The finaly clause will clear out the data sources gracefully // if we don't set the finished signal. // Keep this CLS compliant and just return the array of structures // as returned by the branches.
A populated drag structure. IsEmpty may be true.
A populated drag structure . IsEmpty may be true .
row
int
Target row in the tree
Target row in the tree
nativeColumn
int
The native column
The native column
dragReason
DragReason
The reason for retrieving the drop object
The reason for retrieving the drop object