コード例 #1
0
    public object ItemFromIndex( int index )
    {
      object retval = null;

      this.EnsureNodeTreeCreated();

      GeneratorNodeHelper nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 );

      retval = nodeHelper.FindIndex( index );

      return retval;
    }
コード例 #2
0
    void ICustomItemContainerGenerator.SetCurrentIndex( int newCurrentIndex )
    {
      // This method enables the possibility for the "ItemsHost" panels to set the current item of the 
      // DataGridControl. This is required for scenarios such as the CardflowItemsHost.
      this.EnsureNodeTreeCreated();

      GeneratorNodeHelper nodeHelper = new GeneratorNodeHelper( m_startNode, 0, 0 );

      //First, locate the item within the Generator.
      object newCurrentItem = nodeHelper.FindIndex( newCurrentIndex );

      if( newCurrentItem == null )
        throw new InvalidOperationException( "An attempt was made to access an item at an index that does not correspond to an item." );

      //Then, if the item is within an ItemsNode, check if it belongs to a detail
      ItemsGeneratorNode itemsNode = nodeHelper.CurrentNode as ItemsGeneratorNode;
      if( itemsNode != null )
      {
        int masterIndex;
        int detailIndex;
        int detailNodeIndex;

        DetailGeneratorNode detailNode = itemsNode.GetDetailNodeForIndex( newCurrentIndex - nodeHelper.Index, out masterIndex, out detailIndex, out detailNodeIndex );
        //If it belongs to a detail
        if( detailNode != null )
        {
          //call recursively the SetCurrentIndex method on the detail generator to ensure that if the item
          //belongs to a sub-generator of the detail generator, then the appropriate DataGridContext will get invoked.
          ICustomItemContainerGenerator detailGenerator = detailNode.DetailGenerator;
          detailGenerator.SetCurrentIndex( detailIndex );
          return;
        }
      }

      //If the item is not within an ItemsNode or not within a detail
      //then set it current within its context.
      m_dataGridContext.SetCurrentItemCore( newCurrentItem, false, false );
    }