Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ListView with Image on SubItems

0.00/5 (No votes)
4 Jul 2004 1  
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here