如何使用VB.NET 2005在Treeview中添加ToolStripMenuitem

时间:2012-10-20 06:54:32

标签: vb.net treeview visual-studio-2005

我有如下的Toolstripmenuitem,

enter image description here

使用下面的代码我正在查找结果,

For Each t As ToolStripItem In fobj.MenuStrip1.Items
        Dim parentnode As TreeNode = TreeView1.Nodes.Add(t.Name, t.Name)
        GetMenues(t, menues, parentnode, 1)
        parentnode.Expand()
Next

Public Sub GetMenues(ByVal Current As ToolStripItem, ByRef menues As List(Of ToolStripItem), ByVal parentnode As TreeNode, ByVal s As Integer)
    If Not String.Compare(s.ToString, "1") = 0 Then
        Dim fatherNode As TreeNode = parentnode.Nodes.Add(Current.Name, Current.Name)
    End If
    If TypeOf (Current) Is ToolStripMenuItem Then
        For Each menu As ToolStripItem In DirectCast(Current, ToolStripMenuItem).DropDownItems
            GetMenues(menu, menues, parentnode, s + 1)
        Next
    End If
End Sub

enter image description here

现在我想按照下面的顺序将它添加到树视图中

enter image description here

由于

1 个答案:

答案 0 :(得分:0)

最终我得到了解决这个问题的方法,

Please Refer this Link

本规范通过少量修改解决了这个问题。

由于