ListView question

Started by John Montenigro, February 24, 2014, 12:56:15 AM

Previous topic - Next topic

John Montenigro

I'm trying to detect when the user selects an item in a ListView control, and obtain the text of the selected item. (Then I'll use that text to look up other info from a file and populate textboxes...)

I've tried a number of the events/messages available from FF's control dropbox, but haven't been able to find one that gives me the appropriate action. For example:

Function FRMMAIN_LVPRODUCTID_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, ProductID, temp As String
   
   'get the row of the selected Product from the LV   
   lRow = FF_ListView_GetSelectedItem(hWndControl)

   ...



This works fine on the first click, but if the same or another item is clicked, I see the routine fire 3 times. And the extra processing is a burden.

So, now I'm trying a Custom event, but I'm stuck on what message value to test under WM_NOTIFY

Function FRMMAIN_LVPRODUCTID_CUSTOM ( _
                                      ControlIndex  As Long,  _  ' index in Control Array
                                      hWndForm      As Dword, _  ' handle of Form
                                      hWndControl   As Dword, _  ' handle of Control
                                      wMsg          As Long,  _  ' type of message
                                      wParam        As Dword, _  ' first message parameter
                                      lParam        As Long   _  ' second message parameter
                                      ) As Long
   Select Case As Long wMsg
   Case %WM_NOTIFY 
      'MsgBox "WM_NOTIFY",,"CUSTOM LV MESSAGE"  ' this proves that we're getting here, but what's the next test?
      'If wParam = %LVN_ITEMACTIVATE Or lParam = %LVN_ITEMACTIVATE Then
      If wParam = %LVM_GETITEM Or lParam = %LVM_GETITEM Then     
         MsgBox "wm_notify is recognized!",,"CUSTOM LV MESSAGE"  'not showing up...
         Function = 0
      End If   

   Case %WM_MOUSEWHEEL
      MsgBox "You used the mousewheel"
   End Select       

End Function


Suggestions?

Thanks,
-John



Rudolf Furstauer

There are many examples here in the forum:

'--------------------------------------------------------------------------------
Function FORM1_WM_NOTIFY ( _
                         hWndForm     As Dword,     _  ' handle of Form
                         idCtrl       As Dword,     _  ' control ID
                         ByVal pNMHDR As NMHDR Ptr  _  ' pointer to NMHDR structure
                         ) As Long

   Local lpLvNm As NM_LISTVIEW Ptr

   ' Catch the doubleclick on the Listview (via the WM_NOTIFY for the Form)

   Select Case @pNMHDR.idFrom
      Case IDC_FORM1_LISTVIEW1
         
         lpLvNm = pNMHDR
         Select Case @lpLvNm.hdr.Code
           
            Case %NM_CLICK     'left click
                     
            Case %NM_DBLCLK    'left double-click
           
               ? "Doubleclick on row: " & Format$(FF_ListView_GetSelectedItem(@lpLvNm.hdr.hWndFrom))                       
           
            Case %NM_RCLICK    'right click
           
            Case %NM_RDBLCLK   'right double-click
         
         End Select
   End Select     
End Function


Rudolf

Klaas Holland

Rudolf I think you showed me this.

'--------------------------------------------------------------------------------
Function FORMT2_CUSTOM (hWndForm As Dword, wMsg As Long, wParam As Dword, lParam As Long) As Long
    Local pNmLvw        As NM_LISTVIEW Ptr
    Local RectSub       As Rect

    Select Case wMsg

        Case %WM_NOTIFY
            Select Case LoWrd(wParam)
                Case IDC_FORMT2_LISTVIEW1
                    pNmLvw = lParam

                    If @pNmLvw.hdr.Code = %NM_CLICK And @pNmLvw.iItem > -1 Then
                        gLvRow  = @pNmLvw.iItem
                        gLvCol  = 1   '@pNmLvw.iSubItem
                        EditCell2
                    ElseIf @pNmLvw.hdr.Code = %NM_DBLCLK And @pNmLvw.iItem > -1 Then
                        gLvRow  = @pNmLvw.iItem
                        gLvCol  = @pNmLvw.iSubItem
                        If gLvCol = 2 Then ComboCell2
                        If gLvCol = 4 Then ComboCell2a
                    End If

            End Select

    End Select

End Function


'--------------------------------------------------------------------------------
Sub EditCell2
'--------------------------------------------------------------------------------
    Local RectSub      As Rect
    Local Txt          As String

    FF_ListView_SetSelectedItem HWND_FORMT2_LISTVIEW1, gLvRow
    ListView_EnsureVisible HWND_FORMT2_LISTVIEW1, gLvRow, 0     
    ListView_GetSubItemRect HWND_FORMT2_LISTVIEW1, gLvRow, gLvCol, %LVIR_LABEL, RectSub   
    FF_Control_SetLoc HWND_FORMT2_TEXT1, RectSub.nLeft , RectSub.nTop
    FF_Control_SetSize HWND_FORMT2_TEXT1, RectSub.nRight - RectSub.nLeft , RectSub.nBottom + 5 - RectSub.nTop

    FF_ListView_GetItemText HWND_FORMT2_LISTVIEW1, gLvRow, gLvCol To Txt
    FF_TextBox_SetText HWND_FORMT2_TEXT1, RTrim$(Txt)
    FF_Control_ShowState HWND_FORMT2_TEXT1, %SW_SHOW
    FF_Control_SetFocus HWND_FORMT2_TEXT1

End Sub




Klaas

John Montenigro

Geesh!

I didn't realize I could handle the WM_Notify at the form. Of course, it's in the MSDN, but I didn't get the significance of how to do it in FF...

I'm good now!

Thanks,
-John

Eddy Van Esch

Quote from: John Montenigro on February 24, 2014, 10:40:02 AM
I didn't realize I could handle the WM_Notify at the form.
That's a common mistake. Notification messages are sent to the controls form, rather then to the control itself.
Eddy