private void CategoryTree_BeforeExpand(object sender, System.Windows.Forms.TreeViewCancelEventArgs e) { CategoryTreeNode node = (CategoryTreeNode)e.Node; if (!node.HasDownloadedChildren) { GetChildren(node); } }
private void GetChildren(CategoryTreeNode node) { node.Nodes.Clear(); GetRelatedCategories grc = new GetRelatedCategories(); Category cat = new Category(node.CategoryValue.TModelKey, node.CategoryValue.KeyValue); grc.Categories.Add(cat); // // If the Parent is null, it is a root node (tModel) // if (node.IsSchemeNode) { grc.Categories[0].RelationshipQualifiers.Add(RelationshipQualifier.root); } else { grc.Categories[0].RelationshipQualifiers.Add(RelationshipQualifier.child); } CategoryList list = null; try { list = grc.Send(_connection); } catch (Exception e) { MessageBox.Show(this, e.Message, "Error Loading Tree Node"); return; } CategoryValueCollection values; if (node.IsSchemeNode) { values = list.CategoryInfos[0].Roots; } else { values = list.CategoryInfos[0].Children; } foreach (CategoryValue val in values) { CategoryTreeNode subnode = new CategoryTreeNode(val); subnode.CategoryValue.TModelKey = node.CategoryValue.TModelKey; node.Nodes.Add(subnode); } node.HasDownloadedChildren = true; }
public void LoadTModels( ) { FindTModel ft = new FindTModel(); ft.CategoryBag.Add(CommonCanonical.UddiOrgTypes, "categorization", "Categorization (taxonomy)"); TModelList list = null; try { list = ft.Send(_connection); } catch (Exception e) { MessageBox.Show(this, e.Message, @"Error loading Category Tree", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (null == list) { MessageBox.Show(this, @"An unknown error occurred while loading the Category Tree.", @"Error loading Category Tree", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } GetRelatedCategories grc = new GetRelatedCategories(); Category c = new Category(); c.RelationshipQualifiers.Add(RelationshipQualifier.root); foreach (TModelInfo info in list.TModelInfos) { bool categorization = false; c.TModelKey = info.TModelKey; grc.Categories.Add(c); CategoryList cl = null; try { cl = grc.Send(_connection); categorization = true; } catch (InvalidKeyPassedException) { // // tModel doesn't represent a categorization. So, don't show // it in the tree. // } catch (Exception e) { // // if anything else happened, re-throw & let the app deal with it. // throw e; } if (categorization) { // // Create a new node and wrap the tModelInfo into a // CategoryInfo object. // CategoryTreeNode catnode = new CategoryTreeNode(new CategoryInfo(info.TModelKey)); catnode.Nodes.Clear(); // // Set the Text of the node to the text of the tModel. // catnode.Text = info.Name.Text; CategoryValueCollection values = cl.CategoryInfos[0].Roots; foreach (CategoryValue val in values) { CategoryTreeNode subnode = new CategoryTreeNode(val); subnode.CategoryValue.TModelKey = catnode.CategoryValue.TModelKey; catnode.Nodes.Add(subnode); } catnode.HasDownloadedChildren = true; // // Add the node to the root. // Nodes.Add(catnode); } } }