VS2008 treeview问题
在VS2008VB的环境下treeview控件的节点怎么用代码加上,包括父级和子级的最好给个例子...
在VS2008 VB的环境下 treeview控件的节点怎么用代码加上,包括父级和子级的 最好给个例子
展开
2个回答
展开全部
TreeNode tnP = new TreeNode();//创建一个父节点
tnP.Text = "父";
TreeNode tnC1 = new TreeNode();//创建一个子节点并添加到父节点中
tnC1.Text = "子1";
tnP.Nodes.Add(tnC1);
TreeNode tnC2 = new TreeNode();
tnC2.Text = "子2";
tnP.Nodes.Add(tnC2);
treeView1.Nodes.Add(tnP);//把父节点添加到TreeView控件中
tnP.Text = "父";
TreeNode tnC1 = new TreeNode();//创建一个子节点并添加到父节点中
tnC1.Text = "子1";
tnP.Nodes.Add(tnC1);
TreeNode tnC2 = new TreeNode();
tnC2.Text = "子2";
tnP.Nodes.Add(tnC2);
treeView1.Nodes.Add(tnP);//把父节点添加到TreeView控件中
追问
可以了 非常感谢
展开全部
private void InitData(int bomSID)
{
BomManage bmManage = new BomManage();
MM_BomMain bm = bmManage.GetBomMain(bomSID);
TreeNode rootNode = new TreeNode();
rootNode.Text = bm.CInvCode + " - " + (new InventoryInfo()).GetInventoryName(bm.CInvCode) + " (" + bm.VisionNumber + ")";
rootNode.Value = "-1";
rootNode.NavigateUrl = "#";
PopulateTreeView(bmManage, bomSID, rootNode, true);
this.tvBom.Nodes.Add(rootNode);
}
private void PopulateTreeView(BomManage bmManage,int parentId, TreeNode parentNode, bool bFlag)
{
DataView dv = bmManage.GetNodes(parentId, bFlag).DefaultView;
foreach (DataRowView drv in dv)
{
TreeNode myNode = new TreeNode(drv["InvCode"].ToString() + " - " + (new InventoryInfo()).GetInventoryName(drv["InvCode"].ToString()) + " [" + drv["Quantity"].ToString() + "]");
myNode.Value = drv["SID"].ToString();
myNode.NavigateUrl = "#";
parentNode.ChildNodes.Add(myNode);
PopulateTreeView(bmManage, Convert.ToInt32(drv["SID"].ToString()), myNode, false);
}
}
{
BomManage bmManage = new BomManage();
MM_BomMain bm = bmManage.GetBomMain(bomSID);
TreeNode rootNode = new TreeNode();
rootNode.Text = bm.CInvCode + " - " + (new InventoryInfo()).GetInventoryName(bm.CInvCode) + " (" + bm.VisionNumber + ")";
rootNode.Value = "-1";
rootNode.NavigateUrl = "#";
PopulateTreeView(bmManage, bomSID, rootNode, true);
this.tvBom.Nodes.Add(rootNode);
}
private void PopulateTreeView(BomManage bmManage,int parentId, TreeNode parentNode, bool bFlag)
{
DataView dv = bmManage.GetNodes(parentId, bFlag).DefaultView;
foreach (DataRowView drv in dv)
{
TreeNode myNode = new TreeNode(drv["InvCode"].ToString() + " - " + (new InventoryInfo()).GetInventoryName(drv["InvCode"].ToString()) + " [" + drv["Quantity"].ToString() + "]");
myNode.Value = drv["SID"].ToString();
myNode.NavigateUrl = "#";
parentNode.ChildNodes.Add(myNode);
PopulateTreeView(bmManage, Convert.ToInt32(drv["SID"].ToString()), myNode, false);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询