65.9K
CodeProject is changing. Read more.
Home

Checkable Detail List View

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.25/5 (9 votes)

Apr 4, 2003

viewsIcon

99222

downloadIcon

1642

ListView which supports checkable subitems and returns the clicked subitem

Introduction

When user clicks some content in the ListViewDetail, it returns the row and column indexes of the clicked subitem. This control supports checked subitems through AddCheckedSubItem, SetCheck and IsChecked methods. There is also a routine for iterative coloring of the control included in the TPLib.Misc namespace.

Background

When using the Windows Forms ListView control, you have no way to find which subitem the user has clicked or to have checkable subitems, so I've developed ListViewDetail.

Using the code

Control behaves much like an ordinary ListView. The only difference is in the following methods:

AddCheckedSubItem - adds a checked subitem to ListViewItem

ListViewItem lvi = new ListViewItem();
lvi.Text = "Some text";
listView1.AddCheckedSubItem( lvi, true );
listView1.AddCheckedSubItem( lvi, false );
listView1.AddCheckedSubItem( lvi, true );
listView1.Items.Add( lvi );
SetCheck - sets the check in the subitem to true/false
listView1.SetCheck( listViewItem, colIndex, true );
IsChecked - returns the check state of the subitem
listView1.IsChecked( listViewItem.SubItems[5] )

There is also a class named ListViewOperations which contains two static methods, IterateColors( ListView lv, Color color1, Color color2 ) and IterateColors( ListView lv ) which iteratively set the ListView items' background colors.

IterateColors( lv, Color.White, Color.WhiteSmoke );