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, );
itemA.ImageIndex = ;
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 == ) continue; TreeListViewItem lvItem = new TreeListViewItem(subitem.ProductName, );
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 == ? "yes" : "");
lvItem.SubItems.Add(subitem.SpecialMark);
lvItem.SubItems.Add(subitem.Sort.ToString()); itemA.Items.Add(lvItem); }
tlvProduct.Items.Add(itemA); }
} }
实例二:
/// <summary>
/// 初始化所有分类
/// </summary>
public void InitCategoryData()
{
tlvProduct.Items.Clear(); //查詢所有一級分類
List<ProductMapCategoryInfo> categoryList = ppmBll.GetAllCategoryList();
//查詢所有產品分類
List<ProductMapInfo> productList = ppmBll.GetAllProductMapList(); //一級分類綁定到treeview
foreach (ProductMapCategoryInfo citem in categoryList)
{
TreeListViewItem mainMenu = new TreeListViewItem(citem.CategoryName, );
mainMenu.UseItemStyleForSubItems = false;
mainMenu.SubItems[].ForeColor = ColorTranslator.FromHtml(citem.TitleColor);
mainMenu.Tag = citem;
//查找二級分類
List<ProductMapInfo> productMenuList = productList.FindAll(n => n.CategoryID == citem.ID && n.ParentID == ); foreach (ProductMapInfo productMenu in productMenuList)
{
TreeListViewItem menuNode = new TreeListViewItem(productMenu.PageName, );
menuNode.UseItemStyleForSubItems = false;
menuNode.SubItems[].ForeColor = ColorTranslator.FromHtml(productMenu.TitleColor);
menuNode.Tag = productMenu;
//查找三級分類
List<ProductMapInfo> productSubMenuList = productList.FindAll(n => n.ParentID == productMenu.ID); if (productSubMenuList.Count > )
{ foreach (ProductMapInfo productSubMenu in productSubMenuList)
{
TreeListViewItem subMenuNode = new TreeListViewItem(productSubMenu.PageName, );
subMenuNode.UseItemStyleForSubItems = false;
subMenuNode.SubItems[].ForeColor = ColorTranslator.FromHtml(productSubMenu.TitleColor); subMenuNode.Tag = productSubMenu;
subMenuNode.ImageIndex = productSubMenu.HotFlag;
subMenuNode.SubItems.Add(productMenu.PageKey);
subMenuNode.SubItems.Add(productMenu.IsShopShow.ToString());
subMenuNode.SubItems.Add(productMenu.SmallImageUrl);
subMenuNode.SubItems.Add(productMenu.Sort.ToString());
menuNode.Items.Add(subMenuNode); }
}
else
{ menuNode.ImageIndex = productMenu.HotFlag;
menuNode.SubItems.Add(productMenu.PageKey);
menuNode.SubItems.Add(productMenu.IsShopShow.ToString());
menuNode.SubItems.Add(productMenu.SmallImageUrl);
menuNode.SubItems.Add(productMenu.Sort.ToString()); } mainMenu.Items.Add(menuNode);
} this.tlvProduct.Items.Add(mainMenu);
} }
2