Solved

ListView populated with Tool Strip Menu Items

Posted on 2011-03-24
1
724 Views
Last Modified: 2012-05-11
Hi,
I have maneged to load Tool strip menu items in listview but how can I show coresponding image from tool strip next to the same in list view...
This would be the same as it's created eg in Excel for "Customize command" option in "Tools" menu..
Please help .... I would appreciate a lot...
Code for loading Toolstrip items below...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each tsmi As ToolStripMenuItem In menuStrip1.Items

            getChildNodes(tsmi)

                    Next
    End Sub
    Private Sub getChildNodes(ByVal mi As ToolStripDropDownItem)
        For Each item As Object In mi.DropDownItems
            If item.[GetType]() Is GetType(ToolStripSeparator) Then
                Continue For
            End If
            Dim node As New ListViewItem(DirectCast(item, ToolStripDropDownItem).Text)
            ListView1.Items.Add(node)

            getChildNodes(DirectCast(item, ToolStripDropDownItem))
        Next
    End Sub

Open in new window

0
Comment
Question by:alsam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
ID: 35220875
Hi,

You can do it by using an ImageList control.

So you have to

1- Add an ImageList Control to your form

2-Add to the ImageList Control all the images of the ToolStripMenuItems on the Image Collection you can do this on the properties window of the ImageList on design mode

3-Assign to each ToolStripMenuItems the proper ImageIndex of the ImageList on the Imageindex property of the ToolStripMenuItem, but you have to do this by code

ToolStripMenuItem1.ImageIndex = 0
ToolStripMenuItem2.ImageIndex = 1
etc.

3-Assign to the ListView1 the ImageList control on the SmallImageList Property of the ListView1 for use small images or LargeImageList property for large images, you can do this in the properties window of the ListView on design mode

4-Change your code to assign the ImageIndex of the ToolStripMenu to the ListViewItem when you create it, change this line

Dim node As New ListViewItem(DirectCast(item, ToolStripDropDownItem).Text)

For this one

Dim node As New ListViewItem(DirectCast(item, ToolStripDropDownItem).Text, DirectCast(item, ToolStripDropDownItem).ImageIndex)

Hope that helps
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question