ImageList in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson describes the ImageList control


This component stores a list of images to be used by other controls or by the code.

For example, one way to display an image on a ListView control is to create an ImageList component that will hold the images you want to use:

First drag and drop the control to the Form, and then click the small arrow to its right:

Then choose images you want your ImageList to hold:

Finally set the control's SmallImageList property, selecting your ImageList from the list (ImageList1 in this case):

add this code in the Browse button's click event:

    For Each file As FileInfo In dir.GetFiles
        ' set the image index according extension
        Dim imageindex As Integer = 0
        Select Case file.Extension
            Case ".png", ".jpg", ".bmp", ".gif"
                imageindex = 1
            Case ".txt"
                imageindex = 2
            Case Else
                ' an unknown format so we assign the document image/icon
                imageindex = 0
        End Select

        Dim item As ListViewItem = FilesListView.Items.Add(file.Name, imageindex)
        item.SubItems.Add(String.Format("{0:n2} KB", Convert.ToDouble(file.Length / 1024)))


Previous Lesson | Next Lesson

Share This

Home | About | Contact | Privacy Policy

Copyright 2018 - All Rights Reserved.