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
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
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?
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.
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.
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
Have you tried this?
http://www.planetsquires.com/protect/forum/index.php?topic=2361.0
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
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
I had to turn on FullRowSelect to TRUE :-[
works now, thanks everybody
I was just wondering - thought it had to do something with the listview settings.