PlanetSquires Forums

Support Forums => General Board => Topic started by: Paul Squires on April 16, 2011, 11:19:58 AM

Title: Catching Singleclick and Doubleclick in Listview and ListBox
Post by: Paul Squires on April 16, 2011, 11:19:58 AM
Here is a common question/answer. If you guys know of better ways to handle this then please post your solutions.



'--------------------------------------------------------------------------------
Function FORM1_WM_CREATE ( _
                         hWndForm As Dword, _      ' handle of Form
                         ByVal UserData As Long _  ' optional user defined Long value
                         ) As Long

   
   Local i As Long                         
                         
   ' Fill up the Listview
   FF_ListView_InsertColumn(HWND_FORM1_LISTVIEW1, 0, "ListView Issue", %LVCFMT_LEFT, 200)   
   For i = 0 To 99   
      FF_ListView_InsertItem HWND_FORM1_LISTVIEW1, i, 0, "Column 0  Line" & Str$(i), 0, 0       
   Next                         


   ' Fill up the Listbox
   For i = 0 To 99   
      FF_ListBox_AddString HWND_FORM1_LIST1, "Line" & Str$(i)       
   Next                         

End Function

'--------------------------------------------------------------------------------
Function FORM1_LISTVIEW1_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                                         
   
   If IsTrue (@lpNMV.uNewState And %LVIS_SELECTED) Then
      ' Do whatever you want with the new line that now has focus.
      ' The line number (zero-based) is in @lpNMV.iItem
      FF_TextBox_SetText HWND_FORM1_TEXT2, Format$(@lpNMV.iItem)                       
   End If
   
End Function



'--------------------------------------------------------------------------------
Function FORM1_LIST1_LBN_SELCHANGE ( _
                                   ControlIndex  As Long,  _  ' index in Control Array
                                   hWndForm      As Dword, _  ' handle of Form
                                   hWndControl   As Dword, _  ' handle of Control
                                   idListBox     As Dword  _  ' identifier of listbox
                                   ) As Long

   Local nSelRow As Long
   
   nSelRow = FF_ListBox_GetCurSel( hWndControl )
   
   FF_TextBox_SetText HWND_FORM1_TEXT3, Format$(nSelRow)                       

End Function


'--------------------------------------------------------------------------------
Function FORM1_LIST1_LBN_DBLCLK ( _
                                ControlIndex  As Long,  _  ' index in Control Array
                                hWndForm      As Dword, _  ' handle of Form
                                hWndControl   As Dword, _  ' handle of Control
                                idListBox     As Dword  _  ' identifier of listbox
                                ) As Long

   ' Handle catching a doubleclick in the Listbox
   Local nSelRow As Long
   
   nSelRow = FF_ListBox_GetCurSel( hWndControl )
   
   ? "Doubleclick on row: "&  Format$(nSelRow)                       


End Function


'--------------------------------------------------------------------------------
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