TreeListView的用法
public void ProductBind() { tlvProduct.Items.Clear(); List<ProductInfo> list = ppbll.GetProduct("", ""); List<string> contents = new List<string>(); foreach (ProductInfo item in list) { if (!contents.Contains(item.TypeName)) { contents.Add(item.TypeName); TreeListViewItem itemA = new TreeListViewItem(item.TypeName, 0); itemA.ImageIndex = 0; itemA.Tag = item; // itemA.Expand();//展开 List<ProductInfo> sublist = list.FindAll(n => n.TypeName == item.TypeName); List<string> ctype = new List<string>(); foreach (ProductInfo subitem in sublist) { if (!this.ckShowProcess.Checked && subitem.IsProcess == 1) continue; TreeListViewItem lvItem = new TreeListViewItem(subitem.ProductName, 1); lvItem.Tag = subitem; lvItem.SubItems.Add(subitem.HeadOfficeDiscount.ToString()); lvItem.SubItems.Add(subitem.PringShopDiscount.ToString()); lvItem.SubItems.Add(subitem.ProcessName); lvItem.SubItems.Add(subitem.Label1); lvItem.SubItems.Add(subitem.Label2); lvItem.SubItems.Add(subitem.Label3); lvItem.SubItems.Add(subitem.Label4); lvItem.SubItems.Add(subitem.Label5); lvItem.SubItems.Add(subitem.IsProcess == 1 ? "yes" : ""); lvItem.SubItems.Add(subitem.SpecialMark); lvItem.SubItems.Add(subitem.Sort.ToString()); itemA.Items.Add(lvItem); } tlvProduct.Items.Add(itemA); } } }
实例二:
1 /// <summary> 2 /// 初始化所有分类 3 /// </summary> 4 public void InitCategoryData() 5 { 6 tlvProduct.Items.Clear(); 7 8 //查詢所有一級分類 9 List<ProductMapCategoryInfo> categoryList = ppmBll.GetAllCategoryList(); 10 //查詢所有產品分類 11 List<ProductMapInfo> productList = ppmBll.GetAllProductMapList(); 12 13 //一級分類綁定到treeview 14 foreach (ProductMapCategoryInfo citem in categoryList) 15 { 16 TreeListViewItem mainMenu = new TreeListViewItem(citem.CategoryName, 3); 17 mainMenu.UseItemStyleForSubItems = false; 18 mainMenu.SubItems[0].ForeColor = ColorTranslator.FromHtml(citem.TitleColor); 19 mainMenu.Tag = citem; 20 //查找二級分類 21 List<ProductMapInfo> productMenuList = productList.FindAll(n => n.CategoryID == citem.ID && n.ParentID == 0); 22 23 foreach (ProductMapInfo productMenu in productMenuList) 24 { 25 TreeListViewItem menuNode = new TreeListViewItem(productMenu.PageName, 0); 26 menuNode.UseItemStyleForSubItems = false; 27 menuNode.SubItems[0].ForeColor = ColorTranslator.FromHtml(productMenu.TitleColor); 28 menuNode.Tag = productMenu; 29 //查找三級分類 30 List<ProductMapInfo> productSubMenuList = productList.FindAll(n => n.ParentID == productMenu.ID); 31 32 if (productSubMenuList.Count > 0) 33 { 34 35 foreach (ProductMapInfo productSubMenu in productSubMenuList) 36 { 37 TreeListViewItem subMenuNode = new TreeListViewItem(productSubMenu.PageName, 0); 38 subMenuNode.UseItemStyleForSubItems = false; 39 subMenuNode.SubItems[0].ForeColor = ColorTranslator.FromHtml(productSubMenu.TitleColor); 40 41 subMenuNode.Tag = productSubMenu; 42 subMenuNode.ImageIndex = productSubMenu.HotFlag; 43 subMenuNode.SubItems.Add(productMenu.PageKey); 44 subMenuNode.SubItems.Add(productMenu.IsShopShow.ToString()); 45 subMenuNode.SubItems.Add(productMenu.SmallImageUrl); 46 subMenuNode.SubItems.Add(productMenu.Sort.ToString()); 47 menuNode.Items.Add(subMenuNode); 48 49 } 50 } 51 else 52 { 53 54 menuNode.ImageIndex = productMenu.HotFlag; 55 menuNode.SubItems.Add(productMenu.PageKey); 56 menuNode.SubItems.Add(productMenu.IsShopShow.ToString()); 57 menuNode.SubItems.Add(productMenu.SmallImageUrl); 58 menuNode.SubItems.Add(productMenu.Sort.ToString()); 59 60 } 61 62 mainMenu.Items.Add(menuNode); 63 } 64 65 66 this.tlvProduct.Items.Add(mainMenu); 67 } 68 69 70 71 72 73 }