遍历ProjectTree

函数嵌套方法进行遍历树节点

private void ScanTree()
{
    try
    {
        SGWorld61 sgworld = new SGWorld61();
        int rootID = sgworld.ProjectTree.GetNextItem(0, ItemCode.ROOT);
        TraverseProjectTree(sgworld, rootID);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}
private void TraverseProjectTree(SGWorld61 sgworld,int itemID)
{
    try
    {
        while (itemID > 0)
        {

         string itemName = sgworld.ProjectTree.GetItemName(itemID);
            Console.WriteLine(itemName);

            int childID;

            if (sgworld.ProjectTree.IsGroup(itemID))
            {
                if (!sgworld.ProjectTree.IsLayer(itemID))
                {
                    childID = sgworld.ProjectTree.GetNextItem(itemID, ItemCode.CHILD);
                    TraverseProject(sgworld, childID);
                }
            }
            itemID = sgworld.ProjectTree.GetNextItem(itemID, ItemCode.NEXT);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }               
}

Ps:尽管Skyline中有现成的范例代码,但因为没有仔细看范例代码,还是费了很大的周折才遍历成功,出错地方在childID,真是让人泄气,不得不怀疑我这种粗心大意的人来写代码是不是不合适,汗!

posted on 2013-02-20 17:27  qingqingcao23  阅读(300)  评论(0)    收藏  举报