1. code to move the scroll bar of windows
- Posted by sergelli Feb 28, 2013
- 1167 views
How do I move the scroll bar inside of a listView?
This scroll bar is automatically created by Windows, when the content is larger than the screen.
I tried setVScrollPos (ListView, nnn) and even setVScrollPos ({ListView,SB_VERT}, nnn)
But the first does nothing and the second gives error.
Please, any ideas?
2. Re: code to move the scroll bar of windows
- Posted by ghaberek (admin) Feb 28, 2013
- 1170 views
How do I move the scroll bar inside of a listView?
This scroll bar is automatically created by Windows, when the content is larger than the screen.
I tried setVScrollPos (ListView, nnn) and even setVScrollPos ({ListView,SB_VERT}, nnn)
But the first does nothing and the second gives error.
Please, any ideas?
I would not advise trying to manipulate the scroll bars of system-managed controls; who knows what wrath you may incur. It's best to send the LVM_ENSUREVISIBLE message to the ListView, which scrolls an row into view.
The LVM_ENSUREVISIBLE message is sent automatically by by Win32Lib when you call setIndex(), so you can just use that if it does the job.
However, setIndex() passes false (0) as the second parameter, which tells Windows that the item does not have to be entirely visible (just partially visible). In that case, you can use your own function to force its hand:
public procedure ensureVisible(integer id, integer index, integer entire=0) VOID = w32Func( xSendMessage, {getHandle(id), LVM_ENSUREVISIBLE, index-1, entire}) end procedure -- e.g. ensureVisible( myLV, index, 1 )
Hope this helps,
-Greg
3. Re: code to move the scroll bar of windows
- Posted by LarryMiller Feb 28, 2013
- 1117 views
Standard window messages and functions don't always work with Windows controls. Functions such as setVScrollPos work with windows because the default window procedure is designed to make them work. Windows controls have their own window procedure which does not support this. I have tried all such messages with Listview and other controls without success. I am sure that it could be done with some advanced methods but such solutions tend to be rather fragile and may break with later operating systems. Best avoided.
Unless you really need to scroll to a specific position the LVM_ENSUREVISIBLE message will be simplest and most reliable solution.
If you really must scroll to a specific position the only supported method is to use the LVM_SCROLL message. But be aware that this only allows scrolling relative to the current position. You can tell where that is using the LVM_GETTOPINDEX message (if you are using report view). Depending on what you want to do this could work.