?
Solved

ListView populated with Tool Strip Menu Items

Posted on 2011-03-24
1
Medium Priority
?
730 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 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