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:
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
public class Form1 : System.Windows.Forms.Form
{
private OAKControls.OAKListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources =
new System.Resources.ResourceManager(typeof(Form1));
this.listView1 = new System.Windows.Forms.ListView();
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources =
new System.Resources.ResourceManager(typeof(Form1));
this.listView1 = new OAKControls.OAKListView();
Changing image on subitem
OAKListView.LV_ITEM lvi = new OAKListView.LV_ITEM();
lvi.iItem = 5;
lvi.iSubItem = 5;
lvi.pszText = "OAKListView-" + I.ToString();
lvi.mask = OAKListView.LVIF_IMAGE | OAKListView.LVIF_TEXT;
lvi.iImage = 1;
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.