private void draw(List<Category> categories, Category category, TreeNode node, FormCategories formCategories) { var subCategories = categories.Where(x => x.pc_parent_id == category.pc_id).ToList(); if (subCategories.Count == 0) { drawLeaf(categories, category, node, formCategories); } else { drawNonLeaf(categories, category, node, formCategories); } }
private void drawLeaf(List<Category> categories, Category category, TreeNode node, FormCategories formCategories) { if (node == null) node = formCategories.TreeViewCategories.Nodes.Add(category.pc_id.ToString(), category.pc_name); else node.Nodes.Add(category.pc_id.ToString(), category.pc_name); var subCatID = categoryCharge.Where(x => Convert.ToInt32(x.cc_pc_id) == category.pc_id).Select(c => c.cc_pc_id).FirstOrDefault(); if (subCatID != null) { this.categoryChargeID = Convert.ToInt32(subCatID); } var currentCategory = categories.Where(x => x.pc_id == category.pc_id).FirstOrDefault(); currentCategory.pc_id_from_category_charge = this.categoryChargeID; }
private void drawNonLeaf(List<Category> categories, Category category, TreeNode node) { var subCategories = categories.Where(x => x.pc_parent_id == category.pc_id).ToList(); //Add Node if (node == null) node = treeViewCategories.Nodes.Add(category.pc_id.ToString(), category.pc_name); else node = node.Nodes.Add(category.pc_id.ToString(), category.pc_name); foreach (Category cat in subCategories) { draw(categories, cat, node); } }
private void drawLeaf(Category category, TreeNode node) { if (node == null) node = treeViewCategories.Nodes.Add(category.pc_id.ToString(), category.pc_name); else node.Nodes.Add(category.pc_id.ToString(), category.pc_name); }