PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Shawn Anderson on December 17, 2010, 05:47:17 PM

Title: using ListView
Post by: Shawn Anderson on December 17, 2010, 05:47:17 PM
I've created a listview with 4 columns and populated it with data.

When I click a row, I want to know which row was clicked so I can grab the data from those rows using FF_ListView_GetItemText.

I'm using FF_ListView_GetSelectedItem but it doesn't work right:
ndx=FF_ListView_GetSelectedItem( HWND_name)
I have to click 2 or 3 times to get the right row.

Any suggestions?
thanks
thanks
Title: Re: using ListView
Post by: Elias Montoya on December 17, 2010, 06:00:29 PM

Try...

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

UpdatedRow = @lpNMV.iItem

END FUNCTION
Title: Re: using ListView
Post by: Shawn Anderson on December 17, 2010, 06:14:20 PM
thanks Elias:
that works, but only if I click the first column.

How can I get it to work when I click anywhere on the row?
Title: Re: using ListView
Post by: Elias Montoya on December 17, 2010, 07:32:49 PM
I would store @lpNMV.iItem in a global variable and catch wm_lbuttondown and just retrieve the index from the global variable.

That is because that notification is fired up only when the selection changes, if selection remains the same, just get the old position.
Title: Re: using ListView
Post by: Rolf Brandt on December 18, 2010, 01:45:25 PM
Hello Shawn,

you need to caüture that in the forms custom handler. Enclosed is a small example project with two listviews. The left listview would hold a recordset, the right one displays the data of the current record.

You catch the %NM_CLICK event. That will give you the correct row number. With this you are catching the MouseUp event.

Try the following:
Click on the Listview. Hold the mousebutton down. There is no change in the right listview yet. Release the mousebutton and you will get the correct record.

I can't tell you the Windows interna why LVN_ITEMCHANGED doesn't do it with the mouseclicks. Paul or Jose have an explanation for it. Would be nice also if the WM_LBUTTONUP would give you the proper value.
Title: Re: using ListView
Post by: Klaas Holland on December 18, 2010, 02:57:29 PM
Perhaps this can help.

Function FORMT1_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
    Global gLvRow       As Long
    Global gLvCol       As Long

    Select Case wMsg

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

                    If @pNmLvw.hdr.Code = %NM_CLICK And @pNmLvw.iItem > -1 Then 'Click in listview
                        gLvRow  = @pNmLvw.iItem
                        gLvCol  = @pNmLvw.iSubItem
                        EditCell

                    ElseIf @pNmLvw.hdr.Code = %NM_DBLCLK And @pNmLvw.iItem > -1 Then 'DoubleClick in listview
                        gLvRow  = @pNmLvw.iItem
                        gLvCol  = @pNmLvw.iSubItem
                        ComboCell

                    End If
                End Select

    End Select

End Function

Title: Re: using ListView
Post by: Paul Squires on December 18, 2010, 08:42:26 PM
Have you tried this?

http://www.planetsquires.com/protect/forum/index.php?topic=2361.0
Title: Re: using ListView
Post by: Rolf Brandt on December 19, 2010, 04:12:55 AM
I tried that out too, but it shows the correct data at the second click only. First click will always show the row number of the previous position.

So far for me only the code in the custom event handler works. (Basically the same as Klaas' code.)


Function FORM1_CUSTOM ( _
                      hWndForm      As Dword, _  ' handle of Form
                      wMsg          As Long,  _  ' type of message
                      wParam        As Dword, _  ' first message parameter
                      lParam        As Long   _  ' second message parameter
                      ) As Long

   Local lpNmh  As NMHDR Ptr
   Local lpLvNm As NM_LISTVIEW Ptr
   
   Select Case wMsg
      Case %WM_NOTIFY
         lpNmh = lParam
         
         Select Case @lpNmh.idFrom
            Case IDC_FORM1_LISTVIEW1
            lpLvNm = lParam
            Select Case @LpLvNm.hdr.Code
               Case  %NM_CLICK
                  Call DisplayRec
               Case Else
            End Select
         End Select     
      Case Else
   End Select
End Function

Title: Re: using ListView
Post by: Shawn Anderson on December 20, 2010, 01:17:17 PM
Well I seem to be missing something here.
I can still only see which row was clicked when the first column is clicked.


'--------------------------------------------------------------------------------
Function bu_CUSTOM ( _
                      hWndForm      As Dword, _  ' handle of Form
                      wMsg          As Long,  _  ' type of message
                      wParam        As Dword, _  ' first message parameter
                      lParam        As Long   _  ' second message parameter
                      ) As Long

   Local lpNmh  As NMHDR Ptr
   Local lpLvNm As NM_LISTVIEW Ptr
   Local lLvItem        As Long
   Local lLvSubItem    As Long
   Local ndx As Long

   Select Case wMsg
      Case %WM_NOTIFY
         lpNmh = lParam
         
         Select Case @lpNmh.idFrom
         
            Case IDC_bu_routerlist
            lpLvNm = lParam
            Select Case @LpLvNm.hdr.Code

               Case  %NM_CLICK
                  ' clicked
                  ndx=@lpLvNm.iItem
                 
                  MsgBox Str$(ndx)
               
               Case Else
            End Select
                     
         End Select
     
      Case Else
   End Select
End Function
Title: Re: using ListView
Post by: Shawn Anderson on December 20, 2010, 02:11:29 PM
I had to turn on FullRowSelect to TRUE  :-[
works now, thanks everybody

Title: Re: using ListView
Post by: Rolf Brandt on December 20, 2010, 02:23:52 PM
I was just wondering - thought it had to do something with the listview settings.