src/Misc/EFTools/DesignXmlCore/VirtualTreeGrid/Provider/ColumnPermutation.cs
/// <summary>
///     Change the visible order to match the new order. This allows
///     a secondary ordering permutation, such as that used by the header control,
///     to work well with our permutation. This routine is optimized to expect a
///     single column moving, but will work correctly with any order modification.
/// </summary>
/// <param name="oldOrder">The old order, should correspond to the current display order.</param>
/// <param name="newOrder">The new order. Compare columns to old order to deduce current display order.</param>
Change the visible order to match the new order. This allows
a secondary ordering permutation, such as that used by the header control,
to work well with our permutation. This routine is optimized to expect a
single column moving, but will work correctly with any order modification.
Change the visible order to match the new order . This allows a secondary ordering permutation such as that used by the header control to work well with our permutation . This routine is optimized to expect a single column moving but will work correctly with any order modification .
public void ChangeVisibleColumnOrder(int[] oldOrder, int[] newOrder)
        {
            var columns = myVisibleColumns.Length;
            if (oldOrder.Length != columns
                && newOrder.Length != columns)
            {
                throw new ArgumentException(VirtualTreeStrings.GetString(VirtualTreeStrings.InvalidColumnOrderArrayException));
            }
            var startOrder = oldOrder.Clone() as int[];
            var startIndex = 0;
            var newIndex = 0;
            int startCurrent;
            int newCurrent;
            var totalMarked = 0;
            var permanentlyPassedMarked = 0;
            while (startIndex < columns
                   && newIndex < columns)
            {
                if (-1 == (startCurrent = startOrder[startIndex]))
                {
                    ++startIndex;
                    ++permanentlyPassedMarked;
                }
                else if (startCurrent == (newCurrent = newOrder[newIndex]))
                {
                    ++startIndex;
                    ++newIndex;
                }
                else
                {
                    var passedMarked = 0;
                    var foundStartIndex = -1;
                    int testValue;
                    for (var i = startIndex + 1; i < columns; ++i)
                    {
                        testValue = startOrder[i];
                        if (testValue == newCurrent)
                        {
                            foundStartIndex = i;
                            break;
                        }
                        else if (testValue == -1)
                        {
                            ++passedMarked;
                        }
                    }
                    if (foundStartIndex == -1)
                    {
                        break;
                    }
                    MoveVisibleColumn(foundStartIndex + (totalMarked - permanentlyPassedMarked - passedMarked), newIndex);
                    ++totalMarked;
                    startOrder[foundStartIndex] = -1;
                    ++newIndex;
                }
            }
        }
public void ChangeVisibleColumnOrder ( int [ ] oldOrder , int [ ] newOrder ) { var columns = myVisibleColumns . Length ; if ( oldOrder . Length != columns && newOrder . Length != columns ) { throw new ArgumentException ( VirtualTreeStrings . GetString ( VirtualTreeStrings . InvalidColumnOrderArrayException ) ) ; } var startOrder = oldOrder . Clone ( ) as int [ ] ; var startIndex = 0 ; var newIndex = 0 ; int startCurrent ; int newCurrent ; var totalMarked = 0 ; var permanentlyPassedMarked = 0 ; while ( startIndex < columns && newIndex < columns ) { if ( - 1 == ( startCurrent = startOrder [ startIndex ] ) ) { ++ startIndex ; ++ permanentlyPassedMarked ; } else if ( startCurrent == ( newCurrent = newOrder [ newIndex ] ) ) { ++ startIndex ; ++ newIndex ; } else { var passedMarked = 0 ; var foundStartIndex = - 1 ; int testValue ; for ( var i = startIndex + 1 ; i < columns ; ++ i ) { testValue = startOrder [ i ] ; if ( testValue == newCurrent ) { foundStartIndex = i ; break ; } else if ( testValue == - 1 ) { ++ passedMarked ; } } if ( foundStartIndex == - 1 ) { break ; } MoveVisibleColumn ( foundStartIndex + ( totalMarked - permanentlyPassedMarked - passedMarked ) , newIndex ) ; ++ totalMarked ; startOrder [ foundStartIndex ] = - 1 ; ++ newIndex ; } } }
Change the visible order to match the new order.
Change the visible order to match the new order .
// The algorithm finds the old values in the new array and moves a column // as soon as it is found. To make an accurate move, this means that the // positions that have already moved need to be marked as already processed, // so we duplicate the old array to enable writing to it. // Slot already handle, go look for one that hasn't been // The values are different. The first step is to find the // new value in the old array. We care about the position of // the new value, as well as the number of already handled values // after the located, which can be calculated by seeing how // many marked values we pass on the value. // We're not going to find any more // Update the arrays accordingly // Mark this node as processed // Move to next new item
oldOrder
int[]
The old order, should correspond to the current display order.
The old order should correspond to the current display order .
newOrder
int[]
The new order. Compare columns to old order to deduce current display order.
The new order . Compare columns to old order to deduce current display order .