none
ListView Check Boxes RRS feed

  • Question

  •   I have used ListViews (Visual Studio Visual Basic) many times, and I populate the ListView columns with data using SQL statements that pull data from a database.  I'm now trying to use a ListView with the addition of check boxes.  It was easy enough to get the check boxes to show up in the list view, but I'm wanting to start an event when any of the check boxes within the ListView are checked.  What event should I use?  Thanks...

    Mark
    Saturday, February 21, 2009 4:14 AM

Answers

  •  There are to event ItemCheck and ItemChecked

    Private Sub ListView1_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles ListView1.ItemChecked

    If e.Item.Checked Then

    MessageBox.Show(e.Item.Text)

    End If

    End Sub


    Another is ItemCheck, which fires before ItemChecked, you can modify the check value, like following

    Private Sub ListView1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck

    If e.NewValue = CheckState.Checked And ListView1.Items(e.Index).Text = "Hello" Then

    MessageBox.Show("I am Hello, you cant Check me")

    e.NewValue = CheckState.Unchecked

    End If

    End Sub


    Arjun Paudel
    • Marked as answer by Yichun Feng Friday, February 27, 2009 1:47 AM
    Saturday, February 21, 2009 6:53 AM
  • What you mean by that, you could not find those events? Copy and paste following and just change the handles with name of your control, More Detail about these events are here
    http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.itemchecked.aspx
    http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.itemcheck.aspx

    Private Sub ListView1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck

    End Sub

    Private Sub ListView1_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles ListView1.ItemChecked

    End Sub


    Arjun Paudel
    • Marked as answer by Yichun Feng Friday, February 27, 2009 1:47 AM
    Thursday, February 26, 2009 1:28 AM

All replies

  •  There are to event ItemCheck and ItemChecked

    Private Sub ListView1_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles ListView1.ItemChecked

    If e.Item.Checked Then

    MessageBox.Show(e.Item.Text)

    End If

    End Sub


    Another is ItemCheck, which fires before ItemChecked, you can modify the check value, like following

    Private Sub ListView1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck

    If e.NewValue = CheckState.Checked And ListView1.Items(e.Index).Text = "Hello" Then

    MessageBox.Show("I am Hello, you cant Check me")

    e.NewValue = CheckState.Unchecked

    End If

    End Sub


    Arjun Paudel
    • Marked as answer by Yichun Feng Friday, February 27, 2009 1:47 AM
    Saturday, February 21, 2009 6:53 AM
  • Thanks Arjun.  I will experient with these events.  Thanks again.....
    Saturday, February 21, 2009 6:49 PM
  • Is there a particular library call that needs to be included in the program to make  ItemChecked and ItemCheck available?
    Wednesday, February 25, 2009 11:08 PM
  • What you mean by that, you could not find those events? Copy and paste following and just change the handles with name of your control, More Detail about these events are here
    http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.itemchecked.aspx
    http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.itemcheck.aspx

    Private Sub ListView1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles ListView1.ItemCheck

    End Sub

    Private Sub ListView1_ItemChecked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckedEventArgs) Handles ListView1.ItemChecked

    End Sub


    Arjun Paudel
    • Marked as answer by Yichun Feng Friday, February 27, 2009 1:47 AM
    Thursday, February 26, 2009 1:28 AM