如何用vb处理树形结构

 我来答
百度网友10a24bf
2017-04-10 · TA获得超过1.3万个赞
知道大有可为答主
回答量:1.3万
采纳率:95%
帮助的人:2934万
展开全部
树状结构使用treeview实现,控件添加方法:右击“工具箱”-“部件”-microsoft windows common controls 6.0-确定,应用
下面是简单的添加删除方法,
Option Explicit
‘添加项目
Private Sub Command1_Click()
Dim nodx As Node
Set nodx = TreeView1.Nodes.Add(, , "zf", "紫风无痕关系(双击收起)")
Set nodx = TreeView1.Nodes.Add("zf", tvwChild, "zfwife", "老婆")
Set nodx = TreeView1.Nodes.Add("zf", tvwChild, "zflover", "情人")
Set nodx = TreeView1.Nodes.Add("zf", tvwChild, "zffriend", "朋友")
Set nodx = TreeView1.Nodes.Add("zfwife", tvwChild, "lp1", "大老婆")
Set nodx = TreeView1.Nodes.Add("zfwife", tvwChild, "lp2", "二老婆")
Set nodx = TreeView1.Nodes.Add("zfwife", tvwChild, "lp3", "三老婆")
Set nodx = TreeView1.Nodes.Add("zfwife", tvwChild, "lp4", "四老婆")
Set nodx = TreeView1.Nodes.Add("zfwife", tvwChild, "lp5", "五老婆")
Set nodx = TreeView1.Nodes.Add("zflover", tvwChild, "qr1", "1号情人")
Set nodx = TreeView1.Nodes.Add("zflover", tvwChild, "qr2", "2号情人")
Set nodx = TreeView1.Nodes.Add("zflover", tvwChild, "qr3", "3号情人")
Set nodx = TreeView1.Nodes.Add("zffriend", tvwChild, "py1", "张三")
Set nodx = TreeView1.Nodes.Add("zffriend", tvwChild, "py2", "李四")
Set nodx = TreeView1.Nodes.Add("zffriend", tvwChild, "py3", "王麻子")
Set nodx = TreeView1.Nodes.Add("py1", tvwChild, "pylp1", "张三的老婆")
Set nodx = TreeView1.Nodes.Add("py1", tvwChild, "pylp2", "张三的孩子")
nodx.EnsureVisible
End Sub
'删除代码
Private Sub Command2_Click()
MsgBox ("将要删除" & TreeView1.SelectedItem.Text)
TreeView1.Nodes.Remove (TreeView1.SelectedItem.Index)
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式