Click here to Skip to main content
11,483,003 members (73,173 online)
Click here to Skip to main content

ListView with Image on SubItems

, 4 Jul 2004 CPOL 269.3K 8.6K 90
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)

Share

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 Pin
Member 952275119-Nov-13 23:35
memberMember 952275119-Nov-13 23:35 
Questiondid not appear imagens in subitens Pin
vinao9-Jan-12 8:06
membervinao9-Jan-12 8:06 
AnswerRe: did not appear imagens in subitens Pin
Eric-Paul22-Jan-12 1:37
memberEric-Paul22-Jan-12 1:37 
GeneralRe: did not appear imagens in subitens Pin
atifamin20023-Nov-12 3:30
memberatifamin20023-Nov-12 3:30 
Generalabout param Pin
jason_mf6-Mar-11 22:23
memberjason_mf6-Mar-11 22:23 
GeneralThank you Pin
vherisse25-Feb-09 11:26
membervherisse25-Feb-09 11:26 
QuestionOakListView for VB? Pin
UweSch13-Feb-08 4:35
memberUweSch13-Feb-08 4:35 
AnswerRe: OakListView for VB? Pin
dan neely10-Apr-09 11:34
memberdan neely10-Apr-09 11:34 
Questionhow to chande background color Pin
nits_bhole17-Dec-06 22:32
membernits_bhole17-Dec-06 22:32 
QuestionSubitem icons not appearing Pin
bs999930-Nov-06 6:15
memberbs999930-Nov-06 6:15 
GeneralText color / Background color Pin
obsy1-Jul-06 5:54
memberobsy1-Jul-06 5:54 
GeneralRe: Text color / Background color Pin
Jared James Sullivan13-Nov-06 17:40
memberJared James Sullivan13-Nov-06 17:40 
GeneralRe: Text color / Background color Pin
AcerDad30-Nov-06 13:29
memberAcerDad30-Nov-06 13:29 
QuestionWith C# 2.0 Fix, Still No Subitem Icons? Pin
EarlD11-May-06 16:51
memberEarlD11-May-06 16:51 
AnswerRe: With C# 2.0 Fix, Still No Subitem Icons? Pin
EarlD11-May-06 16:53
memberEarlD11-May-06 16:53 
GeneralRe: With C# 2.0 Fix, Still No Subitem Icons? Pin
klimb902-Jan-08 19:53
memberklimb902-Jan-08 19:53 
AnswerRe: With C# 2.0 Fix, Still No Subitem Icons? Pin
Bertrand Jobert27-Feb-09 2:56
memberBertrand Jobert27-Feb-09 2:56 
GeneralRe: With C# 2.0 Fix, Still No Subitem Icons? Pin
danceinrain1-Mar-09 22:23
memberdanceinrain1-Mar-09 22:23 
QuestionIndenting SubItem ? Pin
PandaPKH18-Apr-06 0:19
memberPandaPKH18-Apr-06 0:19 
AnswerRe: Indenting SubItem ? Pin
yazoox24-Apr-06 22:09
memberyazoox24-Apr-06 22:09 
GeneralRe: Indenting SubItem ? Pin
Synetech1-Oct-08 18:13
memberSynetech1-Oct-08 18:13 
GeneralRe: Indenting SubItem ? Pin
John Simmons / outlaw programmer21-Feb-10 12:48
memberJohn Simmons / outlaw programmer21-Feb-10 12:48 
GeneralRe: Indenting SubItem ? Pin
Synetech21-Feb-10 12:55
memberSynetech21-Feb-10 12:55 
QuestionHow to Find Item with Text Pin
rm_pkt2-Apr-06 20:09
memberrm_pkt2-Apr-06 20:09 
Generalhere is the vb.net version of this smart class Pin
ale75fly21-Mar-06 17:32
memberale75fly21-Mar-06 17:32 

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 | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 5 Jul 2004
Article Copyright 2004 by Carlos Carvalho
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid