Solved

ListView populated with Tool Strip Menu Items

Posted on 2011-03-24
1
709 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
1 Comment
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 500 total points
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now