Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have Toolstripmenuitem as below in Picture1,

Picture1:Click to see the Image

Using the Below code i am geting the result like in Picture2,

VB
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


Picture2:Click to see the Image

Now i want to add this into a treeview in the order like in Picture3:

Picture3:Click to see the Image

Thanks.
Posted
Updated 19-Oct-12 21:22pm
v2

1 solution

Finally i got solution for this Problem,

Please Refer this Link

This Code was solved the problem with small modifications.

Thanks
 
Share this answer
 
Comments
Member 13597231 2-May-18 22:07pm    
you have in vb.net code ? i don't understand covert to vb.net from c#

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900