Getting new value of listview selection...

Started by Anonymous, September 27, 2005, 04:28:29 AM

Previous topic - Next topic

Anonymous

I'm having problems getting the new value of a listview selection.  I want to update other controls on the form based on the new row selected in the listview (whether by mouse, keyboard, etc.)

I tried LVN_ITEMCHANGED and LVN_ITEMCHANGING, but they are not giving me consistent values.  I also searched PB and here and found ListView_GetSelectionMark, but this seems to have the same problem.

This is the code that isn't working for me right now.  I didn't save the many other things I've tried.

Any suggestions?

Thanks!

John


'------------------------------------------------------------------------------------------------------------------------
FUNCTION FRMSEARCHES_LVMAINSEARCH_LVN_ITEMCHANGED ( _
                                                 ControlIndex  AS LONG,            _  ' index in Control Array
                                                 hWndForm      AS DWORD,           _  ' handle of Form
                                                 hWndControl   AS DWORD,           _  ' handle of Control
                                                 BYVAL lpNMV   AS NM_LISTVIEW PTR  _  ' pointer to NM_LISTVIEW
                                                 ) AS LONG
   
   LOCAL lRow AS LONG
   LOCAL sName AS STRING

   lRow = LISTVIEW_GETSELECTIONMARK (HWND_FRMSEARCHES_LVMAINSEARCH)
   
   'If there is no selection, clear the window title, sub search listview, and all text fields.
   IF lRow = -1 THEN
       FF_CONTROL_SETTEXT (HWND_FRMSEARCHES, "Searches")
   END IF

   'Find the currently selected row's name.
   sName = FF_LISTVIEW_GETITEMTEXT (HWND_FRMSEARCHES_LVMAINSEARCH, lRow, 0)

   'Change the window title to reflect this search name.
   FF_CONTROL_SETTEXT (HWND_FRMSEARCHES, "Searches - " & sName)


END FUNCTION

Roger Garstang

SendMessage(HWND_LV, %LVM_GETNEXTITEM, -1, %LVNI_SELECTED)

Anonymous

Thanks Roger!

I put that in LVN_ITEMCHANGED and it works perfectly!

John

Roger Garstang

Cool, the other common one I use is LVNI_FOCUSED if the item is in a multi selection list, or you could continue searching from the found location and gather all those selected.