Hi,
I've got a problem with the ListView control: the ListView is in Report mode and singlesel. When user adds lines to the ListView, they will be appended. Now I want to automatic scroll the listview, so that the added lines are visible. Therefore I must retrieve the index of the top row with Top=FF_ListView_GetTopIndex (HWND_MITGLIED_LISTE). Unfortunately Top is allways zero! And the function RC=ListView_Scroll(HWND_MITGLIED_LISTE,0,5) (5 is only a testvalue) does nothing but RC is TRUE (so it's successfull).
The functions FF_ListView_GetItemCount (HWND_MITGLIED_LISTE) and FF_ListView_GetCountPerPage (HWND_MITGLIED_LISTE) work fine. What's going wrong? Please, can somebody help me?
Rainer
Hello Rainer,
if I understand you right, you are adding rows to the bottom of your listview. Afterwards you want to automatically scroll to the that position.
a& = FF_ListView_GetItemCount (HWND_MITGLIED_LISTE) - 1 'since it is zero based
FF_ListView_SetSelectedItem (HWND_MITGLIED_LISTE, a&)
ListView_EnsureVisible (HWND_MITGLIED_LISTE, a&, 0)
I am using this little function to jump to specific listview items.
'-------------------------------------------------------------------------------
Sub LVSetSelItem(row As Long)
FF_ListView_SetSelectedItem (HwndLV as Dword, row as long)
SetFocus HwndLV
ListView_EnsureVisible HwndLV ,row,0
End Sub
'-------------------------------------------------------------------------------
I had the same problem. Immediate help was provided by Paul. See also this link for further information:
http://planetsquires.com/support/index.php?topic=2233.0 (http://planetsquires.com/support/index.php?topic=2233.0)
Hope that helps.
Rolf Brandt
Hello Rolf,
thanks for your answer - ListView_Ensure Visible works - Great! (You understand right!) But nevertheless the function "ListView_Scroll" doesn't work.
Even when I send the message %LVM_SCROLL it won't work. Why? By the way, FF_ListView_GetItemCount is one based.
Thanks, Rainer
Hello Rainer,
You wrote:
QuoteAnd the function RC=ListView_Scroll(HWND_MITGLIED_LISTE,0,5) (5 is only a testvalue) does nothing but RC is TRUE (so it's successfull).
I assume you understood the ListView_Scroll function wrong. In your example the listview will scroll
5 Pixels down, not 5 rows. Five Pixel will be hardly visible, try a value of 100 or more.
If you want to go to a certain row, try that function
LVSetSelItem from my previous post. If you want to scroll a certain number of rows (let's 5 rows like in your example) then you could use this code:
a& = FF_LISTVIEW_GETSELECTEDITEM (HWND_MITGLIED_LISTE)
Call LVSetSelItem(a& + 5)
Rolf
Hi Rolf,
thanks again - okay, that's it, greater numbers work. But in Win32Api.hlp they said, when it's a ListView in Report-Mode, the value for vertical scroll is rows, not pixel. This seems to be wrong there!
But now my app works and I'm happy!
Thanks and bye
Rainer
The ListView_Scroll help explanation in the old Win32 Help file is a little misleading. Check out the current explanation at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/messages/lvm_scroll.asp
"When the list-view control is in report view, the control can only be scrolled vertically in whole line increments. Therefore, the dy parameter will be rounded to the nearest number of pixels that form a whole line increment. For example, if the height of a line is 16 pixels and 8 is passed for dy, the list will be scrolled by 16 pixels (1 line). If 7 is passed for dy, the list will be scrolled 0 pixels (0 lines)."