Solved

ListView populated with Tool Strip Menu Items

Posted on 2011-03-24
1
716 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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