Click here to Skip to main content
Click here to Skip to main content

ListView with Image on SubItems

, 4 Jul 2004
Rate this:
Please Sign up or sign in to vote.
ListView with Image on SubItems

Introduction

This article describes how to implement ListView with image on subitems. It's very useful in programs that need to show the status of several items.

OAKListView control

This class inherits from the ListView class.

Using the code

Make some change in your code. Add a traditional ListView control to your form and make the changes (in black) as below:

/****************************************************************************/
/// 
/// Summary description for Form1.
/// 
public class Form1 : System.Windows.Forms.Form
{
    // Change this line...
    private System.Windows.Forms.ListView listView1;
    private System.Windows.Forms.ColumnHeader columnHeader1;
    private System.Windows.Forms.ColumnHeader columnHeader2;

/// 
/// Summary description for Form1.
/// 
public class Form1 : System.Windows.Forms.Form
{
    // Like this line...
    private OAKControls.OAKListView listView1;
    private System.Windows.Forms.ColumnHeader columnHeader1;
    private System.Windows.Forms.ColumnHeader columnHeader2;

/****************************************************************************/

/****************************************************************************/
#region Windows Form Designer generated code
/// 
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// 
private void InitializeComponent()
{
    this.components = new System.ComponentModel.Container();
    System.Resources.ResourceManager resources = 
      new System.Resources.ResourceManager(typeof(Form1));
    // Change this line...
    this.listView1 = new System.Windows.Forms.ListView();

#region Windows Form Designer generated code
/// 
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// 
private void InitializeComponent()
{
    this.components = new System.ComponentModel.Container();
    System.Resources.ResourceManager resources = 
      new System.Resources.ResourceManager(typeof(Form1));
    // Like this line...
    this.listView1 = new OAKControls.OAKListView();

/*****************************************************************************/

Changing image on subitem

OAKListView.LV_ITEM lvi = new OAKListView.LV_ITEM();
// Row of the item
lvi.iItem = 5; 
// Column of the item
lvi.iSubItem = 5;
lvi.pszText = "OAKListView-" + I.ToString();
//Here you pass the mask of the item. In this case 
//the mask is the both, Image and the text
lvi.mask = OAKListView.LVIF_IMAGE | OAKListView.LVIF_TEXT; 
// Image index on imagelist
lvi.iImage = 1;
// Sending a message to make the changes
OAKListView.SendMessage(listView1.Handle, 
         OAKListView.LVM_SETITEM, 0, ref lvi);

Conclusion

Most of the functionalities have been described here.

I do not guarantee that this control works 100%. If you find mistakes, you can correct them. This control is not a final release and you can send me mails with explanations if you find bugs or mistakes, and join the modifications if you did them.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Carlos Carvalho
Web Developer
Australia Australia
Carlos Carvalho is a developer and trainer based in Brasil.
He has been developing applications and components since 1995.
He has a large experience in development of several platforms including embedded systems.

Comments and Discussions

 
QuestionAdd SubItem instead of Item PinmemberMember 952275119-Nov-13 22:35 
Questiondid not appear imagens in subitens Pinmembervinao9-Jan-12 7:06 
AnswerRe: did not appear imagens in subitens PinmemberEric-Paul22-Jan-12 0:37 
GeneralRe: did not appear imagens in subitens Pinmemberatifamin20023-Nov-12 2:30 
Generalabout param Pinmemberjason_mf6-Mar-11 21:23 
GeneralThank you Pinmembervherisse25-Feb-09 10:26 
QuestionOakListView for VB? PinmemberUweSch13-Feb-08 3:35 
AnswerRe: OakListView for VB? Pinmemberdan neely10-Apr-09 10:34 
Put the .cs file in a C# project, and add a reference to it from your vb project(s).
 
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall

Questionhow to chande background color Pinmembernits_bhole17-Dec-06 21:32 
QuestionSubitem icons not appearing Pinmemberbs999930-Nov-06 5:15 
GeneralText color / Background color Pinmemberobsy1-Jul-06 4:54 
GeneralRe: Text color / Background color PinmemberJared James Sullivan13-Nov-06 16:40 
GeneralRe: Text color / Background color PinmemberAcerDad30-Nov-06 12:29 
QuestionWith C# 2.0 Fix, Still No Subitem Icons? PinmemberEarlD11-May-06 15:51 
AnswerRe: With C# 2.0 Fix, Still No Subitem Icons? PinmemberEarlD11-May-06 15:53 
GeneralRe: With C# 2.0 Fix, Still No Subitem Icons? Pinmemberklimb902-Jan-08 18:53 
AnswerRe: With C# 2.0 Fix, Still No Subitem Icons? PinmemberBertrand Jobert27-Feb-09 1:56 
GeneralRe: With C# 2.0 Fix, Still No Subitem Icons? Pinmemberdanceinrain1-Mar-09 21:23 
QuestionIndenting SubItem ? PinmemberPandaPKH17-Apr-06 23:19 
AnswerRe: Indenting SubItem ? Pinmemberyazoox24-Apr-06 21:09 
GeneralRe: Indenting SubItem ? PinmemberSynetech1-Oct-08 17:13 
GeneralRe: Indenting SubItem ? PinmemberJohn Simmons / outlaw programmer21-Feb-10 11:48 
GeneralRe: Indenting SubItem ? PinmemberSynetech21-Feb-10 11:55 
QuestionHow to Find Item with Text Pinmemberrm_pkt2-Apr-06 19:09 
Generalhere is the vb.net version of this smart class Pinmemberale75fly21-Mar-06 16:32 
GeneralIcons disapearing after form hide/show Pinmemberjared james sullivan13-Feb-06 15:41 
GeneralRe: Icons disapearing after form hide/show Pinmemberjared james sullivan13-Feb-06 15:53 
GeneralRe: Icons disapearing after form hide/show Pinmemberjared james sullivan13-Feb-06 16:26 
GeneralFix for .NET 2.0 Pinmembershivpal4-Feb-06 6:30 
GeneralRe: Fix for .NET 2.0 Pinmemberyazoox5-Apr-06 21:42 
GeneralRe: Fix for .NET 2.0 PinmemberMalleesh5-Dec-06 23:07 
GeneralRe: Fix for .NET 2.0 Pinmemberroboman29-May-08 21:35 
GeneralRe: Fix for .NET 2.0 PinmemberBabybaer2-Nov-09 22:05 
GeneralImages are left-justified Pinmemberergentrasse15-Dec-05 6:30 
GeneralNo Image shown in SubItems column in c# 2.0 PinmemberDonald Man6-Oct-05 21:45 
GeneralRe: No Image shown in SubItems column in c# 2.0 Pinmemberklemenz3-Nov-05 5:28 
GeneralRe: No Image shown in SubItems column in c# 2.0 Pinmembervovototo24-Dec-05 1:21 
GeneralRe: No Image shown in SubItems column in c# 2.0 PinmemberDustin Aleksiuk13-Jan-06 13:52 
GeneralRe: No Image shown in SubItems column in c# 2.0 Pinmembershivpal4-Feb-06 4:50 
GeneralRe: No Image shown in SubItems column in c# 2.0 Pinmemberyazoox5-Apr-06 21:38 
QuestionRe: No Image shown in SubItems column in c# 2.0 PinmemberCélio3-Jan-07 23:04 
GeneralRe: No Image shown in SubItems column in c# 2.0 Pinmemberzobis16-May-08 10:40 
GeneralRe: No Image shown in SubItems column in c# 2.0 PinmemberSteven Nicholas28-Feb-09 22:33 
QuestionHow to get the text of a listview item. Pinmemberdan neely23-Sep-05 9:25 
GeneralAfter Sorting - Images are Gone PinmemberSumeet_CodeProject26-Jul-05 2:00 
GeneralRe: After Sorting - Images are Gone Pinmemberdan neely23-Sep-05 9:06 
GeneralVB.Net version Pinmemberj1webb4-Mar-05 13:58 
GeneralJuste a detail & image crop PinmemberStyx3122-Feb-05 4:27 
GeneralImagelist control PinmemberDaap16-Dec-04 2:00 
Generaldon't want image in first column PinmemberBlackDice15-Nov-04 9:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 5 Jul 2004
Article Copyright 2004 by Carlos Carvalho
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid