Home > Ask the Microsoft .Net Development Experts > Visual Studio .NET Questions & Answers > How do I add images in listview by using VB.NET?
Ask The Win Development Expert: Questions & Answers
EMAIL THIS

How do I add images in listview by using VB.NET?

Chris Sells EXPERT RESPONSE FROM: Chris Sells

Pose a Question
Other Win Development Categories
Meet all Win Development Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 17 January 2003
How do I add images in listview by using VB.NET?

>
Adding images to most controls on a Form is the same. For example, imagine a form with a tree view, a list view and a toolbar, all needing images, as shown in Figure 1.

Figure 1
Figure 1: Controls without images

Each of these controls takes images from an ImageList component. To add one to the form, drag it from the Windows Forms section of the Toolbox. You can add any number of images to an ImageList component using Property Browser on the ImageList object?s Images property. Pressing the "..." button brings up the Image Collection Editor, as shown in Figure 2.

Figure 2
Figure 2: The Image Collection Editor

Notice that Figure 2 shows several images added to the ImageList component. (I got them from the Common7Graphics folder under my VS.NET installation.) Once you have images in an image list, you can assign them to items in the controls. First, you?ll need to assign an ImageList to the object (a drop-down list will show all of the ImageList objects on the form). Second, you can assign items from the selected ImageList by setting an index into the list of images for a particular item.

For example, assigning an image list to a ListView class requires setting the ImageList for the SmallImageList and/or the LargeImageList, which dictates which image to use based on what view of the ListView is being shown, i.e. small icon or large icon. Second, assigning an image from to an item is a matter of bringing up the ListViewItem Collection Editor by pressing the "..." button next to the Items property and setting the ImageIndex, as shown in Figure 3.

Figure 3
Figure 3: Assigning an image to an item

Images can be set programmatically when items are adding by setting the image index property of the new item:


Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
  Handles MyBase.Load
  ' Add a new item to the ListView
  Dim item As ListViewItem = ListView1.Items.Add("Item6")

  ' Set the index into the image list 
  item.ImageIndex = 6
End Sub 

When images are added from an image list, they show at runtime, as shown in Figure 4.

Figure 4
Figure 4: Images from the image list shown at runtime


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Ask the Expert
Read data from parallel port
Escape from mailto:
In C#, how can I change the properties of controls on another form?
What is the best technique for connecting to a database from VB.NET?
How do you use control collection in VB.NET?
Is ADO.NET record locking no longer an option?
How do I print a form in VB.NET?
How do I get my start page back?
Using an array, how can I create a combo box that lists a dropdown menu for units of length?
How do I determine the type of a control on a Windows Form in VB.NET?

Visual Studio .NET (Archive)
What could be causing this problem with my add New and delete methods?
Is there a .NET equivalent to netsend that I can use in VB.NET?
I'm getting a lot of flickering on my application
How can I make a VB6 network app available on the Internet using .NET?
How can I implement an FTP upload using VB.NET?
VB.NET app works on my local drive but not on the network drive
Is developing add-ons for Windows Explorer supported using managed code in .NET?
In C#, how can I change the properties of controls on another form?
What is the best technique for connecting to a database from VB.NET?
How do you use control collection in VB.NET?

Visual Studio .NET
Load a DSL domain model instance file programmatically
Calling via command prompt from ASP.NET
On line-by-line analysis in VS .NET
Best approach for merging text files using arrays
Descriptions of symbols in the class view of a .NET solution
What's the best approach for enumerating network resources?
How to enable a line-by-line code walkthrough
Changing a C++ Makefile project to a Utility project
How can I configure Visual Studio.NET 2002 to use the .NET Framework 1.1?
Changing a datagrid column to read-only=false based on variable

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Windows Development - White Papers, News and Expert Advice
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts