private void RemoveDetails( ItemsGeneratorNode node, int nodeStartIndex, int nodeEndIndex, int replaceCount )
    {
      if( ( node.Details == null ) || ( node.Details.Count == 0 ) )
        return;

      int removeCount = nodeEndIndex - nodeStartIndex + 1 - replaceCount;
      //Note: If a replace was invoked, replace count will be greater than 0, and will be used to properly re-offset the 
      //details beyond the initial remove range.

      //Note2: for the case of a move or remove, the replace count must remain 0, so that the other details are correctly offseted.

      //first, create an array that will contain the keys for all the expanded details from the ItemsGeneratorNode
      int[] keys = new int[ node.Details.Count ];
      node.Details.Keys.CopyTo( keys, 0 );

      //sort the array, this will prevent any operation that will duplicate keys in the dictionary.
      Array.Sort<int>( keys );

      //cycle through all of the old items
      int countDetailsRemoved = 0;
      foreach( int key in keys )
      {
        //if the key is below the remove range, do not do anything with the dictionary entry

        //If the key match the remove range, remove the dictionary entry ( clear and queue remap )
        if( ( key >= nodeStartIndex ) && ( key <= nodeEndIndex ) )
        {
          List<DetailGeneratorNode> details;
          if( node.Details.TryGetValue( key, out details ) )
          {
            //sum them
            foreach( DetailGeneratorNode detailNode in details )
            {
              countDetailsRemoved += detailNode.ItemCount;
            }
            details.Clear(); //note: detail generators will be "closed" by another section of code (Remap floating details).

#if LOG
            Log.WriteLine( this, "details.Remove - IN" + node.GetHashCode().ToString() + " - Di" + key.ToString() );
#endif

            node.Details.Remove( key );

            if( node.Details.Count == 0 )
            {
              node.Details = null;
            }
          }
          else
          {
            //Key not found in the dictionary, something wrong is going on.
            throw new DataGridInternalException();
          }
        }
        //If the key is above the remove range, re-key it appropriatly.
        else if( key > nodeEndIndex )
        {
          List<DetailGeneratorNode> details;
          if( node.Details.TryGetValue( key, out details ) )
          {
#if LOG
            Log.WriteLine( this, "details.offset for remove - IN" + node.GetHashCode().ToString() + "- Di" + key.ToString() + " - new Di" + ( key - removeCount ).ToString() );
#endif
            node.Details.Remove( key );
            node.Details.Add( key - removeCount, details );
          }
          else
          {
            //Key not found in the dictionary, something wrong is going on.
            throw new DataGridInternalException();
          }
        }
      }

      //if some details have been "disconnected"
      if( countDetailsRemoved > 0 )
      {
        node.AdjustItemCount( -countDetailsRemoved );
      }
    }
    private void OffsetDetails( ItemsGeneratorNode node, int startIndex, int addOffset )
    {
      if( ( node.Details == null ) || ( node.Details.Count == 0 ) )
        return;

      int detailsCount = node.Details.Count;
      //first, create an array that will contain the keys for all the expanded details from the ItemsGeneratorNode
      int[] keys = new int[ detailsCount ];
      node.Details.Keys.CopyTo( keys, 0 );

      //sort the array, this will prevent any operation that will duplicate keys in the dictionary.
      Array.Sort<int>( keys );

      //loop from the end of the sorted array to the beginning. to ensuyre
      for( int i = detailsCount - 1; i >= 0; i-- )
      {
        int key = keys[ i ];

        //only process the key if it is in the processed range
        if( key >= startIndex )
        {
          List<DetailGeneratorNode> details;
          if( node.Details.TryGetValue( key, out details ) )
          {
#if LOG
            Log.WriteLine( this, "details.Offset for Add - IN" + node.GetHashCode().ToString() + "- Di" + key.ToString() + " - new Di" + ( key + addOffset ).ToString() );
#endif
            node.Details.Remove( key );
            node.Details.Add( key + addOffset, details );
          }
          else
          {
            //Key not found in the dictionary, something wrong is going on.
            throw new DataGridInternalException();
          }
        }
      }
    }