示例#1
0
        private GridEntry MoveDownFromItem(GridEntry item, int down_count)
        {
            while (down_count > 0)
            {
                /* if we're a parent node and we're expanded, move to our first child */
                if (item.Expandable && item.Expanded)
                {
                    item = (GridEntry)item.GridItems[0];
                    down_count--;
                }
                else
                {
                    GridItem           searchItem  = item;
                    GridItemCollection searchItems = searchItem.Parent.GridItems;
                    int searchIndex = searchItems.IndexOf(searchItem);

                    while (searchIndex == searchItems.Count - 1)
                    {
                        searchItem = searchItem.Parent;

                        if (searchItem == null || searchItem.Parent == null)
                        {
                            break;
                        }

                        searchItems = searchItem.Parent.GridItems;
                        searchIndex = searchItems.IndexOf(searchItem);
                    }

                    if (searchIndex == searchItems.Count - 1)
                    {
                        /* if we got all the way back to the root with no nodes after
                         * us, the original item was the last one */
                        return(item);
                    }
                    else
                    {
                        item = (GridEntry)searchItems[searchIndex + 1];
                        down_count--;
                    }
                }
            }

            return(item);
        }