Esempio n. 1
0
        //FindItem skips over itemless nodes.
        public int FindItem(object item)
        {
            //finding items can only be done in "forward" direction
            int retval = -1;

            GeneratorNode originalNode            = m_currentNode;
            int           originalIndex           = m_index;
            int           originalSourceDataIndex = m_sourceDataIndex;

            while (retval == -1)
            {
                ItemsGeneratorNode itemsNode = m_currentNode as ItemsGeneratorNode;

                if (itemsNode != null)
                {
                    int tmpIndex = itemsNode.Items.IndexOf(item);
                    if (tmpIndex > -1)
                    {
                        tmpIndex += itemsNode.CountDetailsBeforeDataIndex(tmpIndex);
                        //item is directly from this items node... then return the appropriate index!
                        retval = m_index + tmpIndex;
                        break;
                    }
                    else
                    {
                        //if the item is from a detail, then I don't want to "use" it!!!
                        retval = -1;
                        //but continue looping.... to find occurances of this item somewhere else in the tree
                    }
                }
                else
                {
                    CollectionGeneratorNode collectionNode = m_currentNode as CollectionGeneratorNode;

                    if (collectionNode != null)
                    {
                        int tmpIndex = collectionNode.IndexOf(item);

                        if (tmpIndex != -1)
                        {
                            retval = m_index + tmpIndex;
                            break;
                        }
                    }
                }

                //if we reach this point, it's because the item we are looking
                //for is not in this node... Try to access the child
                if (this.MoveToChild())
                {
                    continue;
                }

                //if we reach this point, it's because we have no child...
                if (this.MoveToNext())
                {
                    continue;
                }

                //final try, try "advancing" to the next item.
                if (this.MoveToFollowing())
                {
                    continue;
                }

                //up to this, we are in an endpoint, we failed.
                break;
            }

            if (retval == -1)
            {
                m_currentNode     = originalNode;
                m_index           = originalIndex;
                m_sourceDataIndex = originalSourceDataIndex;
            }

            return(retval);
        }