private void tvFoodCate_AfterSelect(object sender, TreeViewEventArgs e) { string category = e.Node.Text; if (category.Equals("厨房") || category.Equals("酒吧")) { FoodCategoryService service = new FoodCategoryService(); List<FoodCategory> categorys = service.GetAllCategoryByBelong(category); TreeNode node = tvFoodCate.SelectedNode; node.Nodes.Clear(); foreach (FoodCategory cate in categorys) { node.Nodes.Add(new TreeNode(cate.categoryName)); } node.Expand(); } else { SearchFood(category); } }
private void InitTvFoodCate() { tvFoodCate.Nodes.Clear(); TreeNode node0 = new TreeNode("厨房"); tvFoodCate.Nodes.Add(node0); FoodCategoryService service = new FoodCategoryService(); List<FoodCategory> categorys = service.GetAllCategoryByBelong("厨房"); foreach (FoodCategory cate in categorys) { node0.Nodes.Add(new TreeNode(cate.categoryName)); } node0.Expand(); categorys = service.GetAllCategoryByBelong("酒吧"); TreeNode node1 = new TreeNode("酒吧"); tvFoodCate.Nodes.Add(node1); foreach (FoodCategory cate in categorys) { node1.Nodes.Add(new TreeNode(cate.categoryName)); } node1.Expand(); }