dcsimg
Results 1 to 3 of 3

Thread: Setting Checkboxes in ListView

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    21

    Setting Checkboxes in ListView

    I have a problem setting the checked state of checkboxes in a listview programmatically.

    Background: I have a Windows Form Application which uses CheckedListBox’s. The names/labels for each CheckBox in the list are imported for a database. Also in the database is a field which defines whether the CheckBox should be Checked or Unchecked. The program works fine.

    Problem: My requirement is to add a tooltip to each item in the list of checkboxes. I have read that the best/easiest way to do this is to use a ListView instead of the CheckedListBox. I have setup a ListView with CheckBoxes = True and View = Details. I have populated the ListView with the items from my database. The ListView now looks exactly like the CheckedListBox and the tooltips work fine.

    My problem is that I can’t seem to find a way of setting the CheckBox’s to Checked programmatically. Is there a way to do this, or is there a better way of achieving what I am trying to do?

    I hope I have provided enough information.

    Thanks in advance.

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Setting Checkboxes in ListView

    The ListViewItem has a checked property, that lets you set the CheckBox state. If you set it to True, then an item will be checked:

    Code:
            For i = 0 To 100
                Dim li As ListViewItem = ListView1.Items.Add("Hello")
                If i Mod 3 = 0 Then
                    li.Checked = True
                End If
            Next

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2009
    Posts
    21

    Re: Setting Checkboxes in ListView

    Thanks, sorted.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width