Announcement

Collapse
No announcement yet.

ListView: Unselect All?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • ListView: Unselect All?

    I'm overlooking something, or it's not an API call, where you can unselect all the items in a ListView with a single call. Thought this would work:

    vStyle = GetWindowLong(hList, %GWL_STYLE)
    SetWindowLong hList, %GWL_STYLE, vStyle OR %LVS_SINGLESEL
    SetWindowLong hList, %GWL_STYLE, vStyle
    ListView_SetItemState(hList, hItem, %LVIS_SELECTED, %LVIS_SELECTED)

    But apparently not, any previous selections are still selected.
    Furcadia, an interesting online MMORPG in which you can create and program your own content.

  • #2
    >ListView_SetItemState(hList, hItem, %LVIS_SELECTED, %LVIS_SELECTED)

    This line sets the selected state of zero-based row number 'hitem' to 'selected.'

    To unselect an item, make wParam zero (FALSE)

    To make your code as shown affect any row other than row zero you will need to set 'hitem' to the 'row number of interest'

    Nope, can't unselect 'em all in one shot (with a multi-selection listview). With a single-selection listview, just set hitem (row) to -1& and call your original code above. Well, "maybe" using -1& with a mult-selection control would work. Give it a try.

    But I'm not all that sure you can change from multi-select to single-select on the fly like that.

    Note also, that there is a separate LVIS_FOCUSED state. I usually set FOCUSED and SELECTED the same so the cursor goes to the selected item.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      ListView_SetItemState(hList, -1, %LVIS_SELECTED, %LVIS_SELECTED)
      Was a failure of epic status, it selected EVERYTHING!

      Guess I'm going to have to loop through the listview and unselect all selected items manually, bummer.
      Furcadia, an interesting online MMORPG in which you can create and program your own content.

      Comment


      • #4
        Jackpot!

        Careful reading of the SDK:
        Code:
        ListView_SetItemState(
            HWND hwnd,
            int i,
            UINT state,
            UINT mask
        );
        i
        Index of the list-view item. If this parameter is -1, then the state change is applied to all items.
        state
        New state bits for the item. The mask parameter indicates the valid bits of the state parameter. The macro ignores bits in the state parameter if the corresponding bit is not set in the mask parameter.
        mask
        Bits of the state parameter that you want to set or clear. You can use ListView_SetItemState both to set and to clear bits.
        So:
        Code:
        ListView_SetItemState(hList, -1, 0, %LVIS_SELECTED)
        ListView_SetItemState(hList, hItem, %LVIS_SELECTED, %LVIS_SELECTED)
        ListView_EnsureVisible(hList, hItem, %FALSE)
        Deselects everything and then selects the one I am interested in, bringing it into view.
        Furcadia, an interesting online MMORPG in which you can create and program your own content.

        Comment

        Working...
        X