src/Misc/EFTools/DesignXmlCore/VirtualTreeGrid/Provider/VirtualTree.cs
/// <summary>
///     Delete specific items without calling Realign
/// </summary>
/// <param name="branch">The branch where items have been removed</param>
/// <param name="start">The first item to deleted</param>
/// <param name="count">The number of items to delete</param>
Delete specific items without calling Realign
Delete specific items without calling Realign
protected void DeleteItems(IBranch branch, int start, int count)
        {
            var tn = LocateTrackedNode(branch);
            Debug.Assert(tn != null); 
            if (start >= 0
                && start < tn.ImmedCount)
            {
                TREENODE tnChild;
                TREENODE tnPrevChild;
                var endKillRange = start + count;
                int killCount;
                var enableSingleColumnEvent = GetStateFlag(TreeStateFlags.FireSingleColumnItemCountChanged);
                var enableNormalEvent = ItemCountChanged != null || OnDisplayDataChanged != null;
                var notify = (count != 0) && (enableNormalEvent || enableSingleColumnEvent);
                while (tn != null)
                {
                    var absIndex = -1;
                    var singleColumnAbsIndex = -1;
                    var notifyColumn = 0;
                    if (notify)
                    {
                        var tnNext = tn;
                        var coord = EnumAbsoluteIndices(start, ref tnNext, out singleColumnAbsIndex);
                        if (coord.IsValid)
                        {
                            absIndex = coord.Row;
                            notifyColumn = coord.Column;
                        }
                    }
                    killCount = count;
                    tnChild = tn.FirstChild;
                    tnPrevChild = null;
                    while (tnChild != null)
                    {
                        if (start <= tnChild.Index)
                        {
                            break;
                        }
                        tnPrevChild = tnChild;
                        tnChild = tnChild.NextSibling;
                    }
                    while (tnChild != null)
                    {
                        if (tnChild.Index < endKillRange)
                        {
                            if (tnChild.Expanded)
                            {
                                killCount += tnChild.FullCount;
                            }
                            if (tnPrevChild == null)
                            {
                                tn.FirstChild = tnChild.NextSibling;
                            }
                            else
                            {
                                tnPrevChild.NextSibling = tnChild.NextSibling;
                            }
                            FreeRecursive(ref tnChild);
                            if (tnPrevChild == null)
                            {
                                tnChild = tn.FirstChild;
                            }
                            else
                            {
                                tnChild = tnPrevChild.NextSibling;
                            }
                        }
                        else
                        {
                            tnChild.Index -= count;
                            tnChild = tnChild.NextSibling;
                        }
                    }
                    tn.ImmedCount -= count;
                    ChangeFullCountRecursive(tn, -killCount, 0 );
                    if (notify)
                    {
                        if (enableNormalEvent && absIndex != -1)
                        {
                            if (tn.ComplexSubItem
                                && tn.TotalCount == 0)
                            {
                                if (OnDisplayDataChanged != null)
                                {
                                    OnDisplayDataChanged(
                                        this,
                                        new DisplayDataChangedEventArgs(this, VirtualTreeDisplayDataChanges.All, absIndex, -1, killCount));
                                }
                            }
                            else if (ItemCountChanged != null)
                            {
                                DelayTurnOffRedraw();
                                ItemCountChanged(
                                    this,
                                    new ItemCountChangedEventArgs(
                                        this, absIndex - 1, notifyColumn, -killCount, absIndex - 1, 0, null, false));
                            }
                        }
                        if (enableSingleColumnEvent && singleColumnAbsIndex != -1)
                        {
                            DelayTurnOffSingleColumnRedraw();
                            var singleTree = SingleColumnTree;
                            (singleTree as SingleColumnView).myItemCountChanged(
                                singleTree,
                                new ItemCountChangedEventArgs(
                                    singleTree, singleColumnAbsIndex - 1, 0, -killCount, singleColumnAbsIndex - 1, 0, null, false));
                        }
                    }
                    tn = tn.NextNode;
                }
                ClearPositionCache(); 
            }
        }
protected void DeleteItems ( IBranch branch , int start , int count ) { var tn = LocateTrackedNode ( branch ) ; Debug . Assert ( tn != null ) ; if ( start >= 0 && start < tn . ImmedCount ) { TREENODE tnChild ; TREENODE tnPrevChild ; var endKillRange = start + count ; int killCount ; var enableSingleColumnEvent = GetStateFlag ( TreeStateFlags . FireSingleColumnItemCountChanged ) ; var enableNormalEvent = ItemCountChanged != null || OnDisplayDataChanged != null ; var notify = ( count != 0 ) && ( enableNormalEvent || enableSingleColumnEvent ) ; while ( tn != null ) { var absIndex = - 1 ; var singleColumnAbsIndex = - 1 ; var notifyColumn = 0 ; if ( notify ) { var tnNext = tn ; var coord = EnumAbsoluteIndices ( start , ref tnNext , out singleColumnAbsIndex ) ; if ( coord . IsValid ) { absIndex = coord . Row ; notifyColumn = coord . Column ; } } killCount = count ; tnChild = tn . FirstChild ; tnPrevChild = null ; while ( tnChild != null ) { if ( start <= tnChild . Index ) { break ; } tnPrevChild = tnChild ; tnChild = tnChild . NextSibling ; } while ( tnChild != null ) { if ( tnChild . Index < endKillRange ) { if ( tnChild . Expanded ) { killCount += tnChild . FullCount ; } if ( tnPrevChild == null ) { tn . FirstChild = tnChild . NextSibling ; } else { tnPrevChild . NextSibling = tnChild . NextSibling ; } FreeRecursive ( ref tnChild ) ; if ( tnPrevChild == null ) { tnChild = tn . FirstChild ; } else { tnChild = tnPrevChild . NextSibling ; } } else { tnChild . Index -= count ; tnChild = tnChild . NextSibling ; } } tn . ImmedCount -= count ; ChangeFullCountRecursive ( tn , - killCount , 0 ) ; if ( notify ) { if ( enableNormalEvent && absIndex != - 1 ) { if ( tn . ComplexSubItem && tn . TotalCount == 0 ) { if ( OnDisplayDataChanged != null ) { OnDisplayDataChanged ( this , new DisplayDataChangedEventArgs ( this , VirtualTreeDisplayDataChanges . All , absIndex , - 1 , killCount ) ) ; } } else if ( ItemCountChanged != null ) { DelayTurnOffRedraw ( ) ; ItemCountChanged ( this , new ItemCountChangedEventArgs ( this , absIndex - 1 , notifyColumn , - killCount , absIndex - 1 , 0 , null , false ) ) ; } } if ( enableSingleColumnEvent && singleColumnAbsIndex != - 1 ) { DelayTurnOffSingleColumnRedraw ( ) ; var singleTree = SingleColumnTree ; ( singleTree as SingleColumnView ) . myItemCountChanged ( singleTree , new ItemCountChangedEventArgs ( singleTree , singleColumnAbsIndex - 1 , 0 , - killCount , singleColumnAbsIndex - 1 , 0 , null , false ) ) ; } } tn = tn . NextNode ; } ClearPositionCache ( ) ; } }
Delete specific items without calling Realign
Delete specific items without calling Realign
//Expect LocateTrackedNode to throw otherwise // We need to get the notification index before deleting anything /*UNDONE_MC*/ // UNDONE_MC: See comments in InsertItems. Fold the notifications // for the three size changes into one, and get enough info // back to do multi column. For example, the ComplexSubItem check // in this if statement is equivalent to the output rowIncr parameter // from the more complex ChangeFullCountRecursive call. // UNDONE_NOW: //ItemsDeleted(this, absIndex, killCount); //Cached absolute information is toast.
branch
IBranch
The branch where items have been removed
The branch where items have been removed
start
int
The first item to deleted
The first item to deleted
count
int
The number of items to delete
The number of items to delete