下面是简单的添加删除方法,
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
拖一个ContextMenuStrip控件到界面上,起个名字cms,设置菜单后,并双击实现菜单的点击事件!!最后设置treeview的ContextMenuStrip的属性绑定cms就可以了!!
先在窗体上添加菜单(如:mnucd),然后在treeview控件的MouseDown事件中输入:If Button = 2 Then PopupMenu mnucd
即可
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)