我对用catia结构进行编程并在树视图中创建structre存有疑问。我已经设法创建了多达2个级别,但是当有更多级别时,它就会中断。想知道我如何使其递归的方法。在下面发布我的代码部分。谢谢!
private void GetLinks(ProductStructureTypeLib.Product ProdPar, TreeNode rootnode)
{
MytreeView.Nodes.Add(rootnode);
MytreeView.Nodes.Add(rootnode);
if (ProdPar.Products.Count > 0)
{
foreach (ProductStructureTypeLib.Product child in ProdPar.Products)
{
INFITF.Document childDoc = (INFITF.Document)child.ReferenceProduct.Parent;
TreeNode childnode = new TreeNode();
childnode.Text = childDoc.get_Name();
treeList.Add(childDoc.get_Name());
rootnode.Nodes.Add(childnode);//childnode added--level 1
if (!IsDocumentAPart(childDoc))
{
ProductStructureTypeLib.Product prodRoot;
ProductStructureTypeLib.ProductDocument prodDoc;
prodDoc = (ProductStructureTypeLib.ProductDocument)childDoc;
prodRoot = prodDoc.Product;
if (prodRoot.Products.Count > 0)
{
ReadLinksChild(prodRoot, childnode);
}
}
}
}
private void ReadLinksChild(ProductStructureTypeLib.Product ProdPar, TreeNode node)
{
try
{
foreach (ProductStructureTypeLib.Product child in ProdPar.Products)
{
INFITF.Document childDoc = (INFITF.Document)child.ReferenceProduct.Parent;
TreeNode childnode = new TreeNode();
childnode.Text = childDoc.get_Name();
node.Nodes.Add(childnode);//childnode added--level 1
if (!IsDocumentAPart(childDoc))
{
ProductStructureTypeLib.Product prodRoot;
ProductStructureTypeLib.ProductDocument prodDoc;
prodDoc = (ProductStructureTypeLib.ProductDocument)childDoc;
prodRoot = prodDoc.Product;
if (prodRoot.Products.Count > 0)
{
ReadLinkedDocsProductChild(prodRoot, childnode);
}
}
}
}
catch (Exception ex)
{
logs.Info(ex.ToString());
}
}