none
Listview with CheckBoxes RRS feed

  • Question

  • Hi,

    I would like to display listview with checkboxes (ListView.CheckBoxes = True) but when I select the items the checkboxes are not selected (of course .MultiSelect = True).

    Also I would like to enable working with SHIFT key like in Option 2 Extended in regular list box.

    Comment: when I select the rows or items in listview the items are selected but the checkboxes are not selected I check it by looping listview items

    I would like listview to work like listbox so if you select items the checkboxes will also select

    Is it possible?

    Thanks,


    Guy Zommer


    • Edited by Guy Zommer Tuesday, October 22, 2013 7:39 AM Add picture
    Tuesday, October 22, 2013 7:36 AM

Answers

  • Okay I see.

    I tried using some code with the KeyDown event to detect Shift and previous selection to current.

    Problem is that the KeyDown is not detected if the checkboxes were used to select an item.

    Unless you can hook into the keystroke with some API calls I think, unfortunately, you are fighting a losing battle.


    Cheers,

    Andy
    www.andypope.info

    • Marked as answer by Guy Zommer Wednesday, October 23, 2013 4:42 AM
    Tuesday, October 22, 2013 12:37 PM

All replies

  • Selecting and Checking are 2 discrete actions.

    If you want them to act as one you will need to add code.

    You can capture the Check and or Click events, as I assume you are currently doing.


    Cheers,

    Andy
    www.andypope.info

    Tuesday, October 22, 2013 10:39 AM
  • Thanks,

    I added a code both for the click event and also for the check event.

    How can I select a range of "check boxes" with shift by selecting range of items?

    This is the click code:

    Private Sub ListView1_Click()

    Dim TheItem As ListItem

    For Each TheItem In ListView1.ListItems
        If TheItem.Selected = True Then
            TheItem.Checked = True
        Else
            TheItem.Checked = False
        End If
    Next

    End Sub

    this is the check code:

    Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)

    For Each Item In ListView1.ListItems
        If Item.Checked = True Then
            Item.Selected = True
        Else
            Item.Selected = False
        End If
    Next

    End Sub

    Thanks!


    Guy Zommer

    Tuesday, October 22, 2013 10:47 AM
  • Currently the only thing that is not working is selecting by SHIFT for the checkboxes


    Guy Zommer

    Tuesday, October 22, 2013 10:47 AM
  • The listview does that automatically for me.

    If 1 select 2nd item, hold shift and select 5th item. Then items 2,3,4 and 5 are selected.


    Cheers,

    Andy
    www.andypope.info

    Tuesday, October 22, 2013 11:53 AM
  • Hi,

    This done only if you select the items try to do it on checkbox then you will see what I am talking about

    Thanks


    Guy Zommer

    Tuesday, October 22, 2013 12:05 PM
  • Okay I see.

    I tried using some code with the KeyDown event to detect Shift and previous selection to current.

    Problem is that the KeyDown is not detected if the checkboxes were used to select an item.

    Unless you can hook into the keystroke with some API calls I think, unfortunately, you are fighting a losing battle.


    Cheers,

    Andy
    www.andypope.info

    • Marked as answer by Guy Zommer Wednesday, October 23, 2013 4:42 AM
    Tuesday, October 22, 2013 12:37 PM
  • Thanks Andy

    Guy Zommer

    Wednesday, October 23, 2013 4:42 AM