Announcement

Collapse
No announcement yet.

Misbehaving Listview and %LVM_GETSELECTIONMARK

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

  • Misbehaving Listview and %LVM_GETSELECTIONMARK

    I have a listview that is single selection only, so I use %LVM_GETSELECTIONMARK to get the selected item. If no item is selected the code does nothing, and if selected it performs an action using values from the selected item. %LVM_GETSELECTIONMARK is supposed to return -1 if an item isn't selected, but it is possible to Select an item and then click a blank area of the listview to select no item...this is fine and works nice if they change their mind, etc. The problem is that when they click in a blank area the selection is gone, but the focus/dotted rectangle remains and when %LVM_GETSELECTIONMARK is called it returns the item index with the focus rectangle still.

    To fix this I decided to use %LVN_ITEMCHANGED and expected it to have a @nmlv.uNewState with %LVIS_SELECTED off and %LVIS_FOCUSED on...or maybe even an old state of selected and a new of focused, etc...but this isn't the case. In fact, the only thing I have found to work that removes this phantom Focus Rectangle is:

    Code:
    Case %LVN_ITEMCHANGED
        nmlv= lParam
        If ((@nmlv.uNewState And %LVIS_SELECTED) = 0) And ((@nmlv.uNewState And %LVIS_FOCUSED) = 0) Then ' clicked off all items
            lvi.stateMask= %LVIS_FOCUSED Or %LVIS_SELECTED
            SendMessage(HWND_ListView, %LVM_SETITEMSTATE, @nmlv.iItem, VarPtr(lvi))
        End If
    I would think this would make an endless loop since once changed to 0 it would fire again with a new state of 0 and be changed again, etc...but it doesn't. Is this supposed to work like this?
    Last edited by Roger Garstang; 17 Apr 2008, 09:18 AM.
    sigpic
    Mobile Solutions
    Sys Analyst and Development

  • #2
    What is worse, is even though this works and no item is selected or has a focus rectangle...%LVM_GETSELECTIONMARK still returns the last item selected???
    sigpic
    Mobile Solutions
    Sys Analyst and Development

    Comment


    • #3
      Well, I was going to post this from the SDK doc...
      LVM_GETSELECTIONMARK
      ....
      Remarks

      The selection mark is the item index from which a multiple selection starts.
      .. and suggest that using LVM_GETSELECTIONMARK with a single-select listview might not be optimal.

      What is worse, is even though this works and no item is selected or has a focus rectangle
      LVIS_SELECTED and LVIS_FOCUSED are independent state values. If the item is 'not selected' you should be able to set the focused state off at that time also using Listview_SetItemState. (I think? Worth a try anyway).

      Or, you might try doing your thing on the LVN_ITEMCHANGING notification and reject the change depending on application conditions.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment

      Working...
      X