Click here to Skip to main content
Licence CPOL
First Posted 4 Jul 2004
Views 215,420
Bookmarked 84 times

ListView with Image on SubItems

By | 4 Jul 2004 | Article
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

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questiondid not appear imagens in subitens Pinmembervinao7:06 9 Jan '12  
AnswerRe: did not appear imagens in subitens PinmemberEric-Paul0:37 22 Jan '12  
Generalabout param Pinmemberjason_mf21:23 6 Mar '11  
GeneralThank you Pinmembervherisse10:26 25 Feb '09  
QuestionOakListView for VB? PinmemberUweSch3:35 13 Feb '08  
AnswerRe: OakListView for VB? Pinmemberdan neely10:34 10 Apr '09  
Questionhow to chande background color Pinmembernits_bhole21:32 17 Dec '06  
QuestionSubitem icons not appearing Pinmemberbs99995:15 30 Nov '06  
GeneralText color / Background color Pinmemberobsy4:54 1 Jul '06  
GeneralRe: Text color / Background color PinmemberJared James Sullivan16:40 13 Nov '06  
GeneralRe: Text color / Background color PinmemberAcerDad12:29 30 Nov '06  
QuestionWith C# 2.0 Fix, Still No Subitem Icons? PinmemberEarlD15:51 11 May '06  
AnswerRe: With C# 2.0 Fix, Still No Subitem Icons? PinmemberEarlD15:53 11 May '06  
GeneralRe: With C# 2.0 Fix, Still No Subitem Icons? Pinmemberklimb9018:53 2 Jan '08  
AnswerRe: With C# 2.0 Fix, Still No Subitem Icons? PinmemberBertrand Jobert1:56 27 Feb '09  
GeneralRe: With C# 2.0 Fix, Still No Subitem Icons? Pinmemberdanceinrain21:23 1 Mar '09  
QuestionIndenting SubItem ? PinmemberPandaPKH23:19 17 Apr '06  
AnswerRe: Indenting SubItem ? Pinmemberyazoox21:09 24 Apr '06  
GeneralRe: Indenting SubItem ? PinmemberSynetech17:13 1 Oct '08  
GeneralRe: Indenting SubItem ? PinmemberJohn Simmons / outlaw programmer11:48 21 Feb '10  
GeneralRe: Indenting SubItem ? PinmemberSynetech11:55 21 Feb '10  
QuestionHow to Find Item with Text Pinmemberrm_pkt19:09 2 Apr '06  
Generalhere is the vb.net version of this smart class Pinmemberale75fly16:32 21 Mar '06  
GeneralIcons disapearing after form hide/show Pinmemberjared james sullivan15:41 13 Feb '06  
GeneralRe: Icons disapearing after form hide/show Pinmemberjared james sullivan15:53 13 Feb '06  

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.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 5 Jul 2004
Article Copyright 2004 by Carlos Carvalho
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid