As with menus, list views can display checkboxes; all you have to do is to set their CheckBoxes property to True. You can see how this works in the ListViews example on the CD-ROM if you click the "Add check boxes" button, which sets the CheckBoxes property of ListView1 to True:
Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ListView1.CheckBoxes = True End Sub
To handle checkbox events, I add code to the list view's ItemCheck event. In that event handler, I can take a look at the new setting of the item by examining the NewValue property of the ItemCheckEventArgs object passed to us, and get the index of the item in the list view with the Index property. Here's how I report what item was checked or unchecked in the ListViews example:
Private Sub ListView1_ItemCheck(ByVal sender As Object, _ ByVal e As System.Windows.Forms.ItemCheckEventArgs) _ Handles ListView1.ItemCheck If e.NewValue = CheckState.Checked Then TextBox1.Text = "You checked item " & (e.Index() + 1) Else TextBox1.Text = "You unchecked item " & (e.Index() + 1) End If End Sub
And you can see the results in Figure 10.17, where I've added checkboxes to the list view and checked item 2.