问题描述:

I've table in database ItemList that hold ProdutID with ItemID.

ProductID ItemID

AAA 1001

AAA 1002

AAA 1003

BBB 1201

BBB 1293

CCC 1040

DDD 2011

DDD 3203

I want add all those data to Treeview Like this:

+AAA

- 1001

- 1002

- 1003

+BBB

- 1201

- 1293

+CCC

- 1040

+DDD

- 2011

- 3203

please teach me how to do this. Thanks.

edit :

i try to add each item into ArrayList with length 2 data (ProductID, ItemID)

 for(int i=0;i<arrayList.count;i++)

{

TreeNode treeNode = new TreeNode(((string[])arrayList[i])[0]);

treeview1.Nodes.Add(treeNode);

}

网友答案:
TreeGridNode nodeParent = treeGridView1.Nodes.Add("AAA");

TreeGridNode nodeChild = nodeParent.Nodes.Add("1001"); 
TreeGridNode nodeChild = nodeParent.Nodes.Add("1002"); 
TreeGridNode nodeChild = nodeParent.Nodes.Add("1003"); 

You would do this dynamically using two for loops

foreach (var product in Products)
{
  TreeGridNode nodeParent = treeGridView1.Nodes.Add(product.Id);
  foreach (var item in product.Items)
  {
   TreeGridNode nodeChild = nodeParent.Nodes.Add(item.Id); 
  }

}
相关阅读:
Top