ListBox - How to detect a vertical scroll movement?

73 views
Skip to first unread message

Neville Lang

unread,
Nov 28, 2004, 10:37:53 AM11/28/04
to
Hi all,

In CF, if a ListBox has more items in its datasource than it can display, it
automatically shows a vertical scroll bar. I have a need to detect when the
scroll bar has been clicked by the user, either stepped by one using the
arrow or stepped by a page-full, causing the list to change. There does not
seem to be any standard ListBox events in CF that let me know when the list
has changed when using the scroll bar. Is there any way I can detect when
either the scroll bar has been clicked or the ListBox listing has changed?

Regards,
Neville Lang


Daniel Moth

unread,
Nov 28, 2004, 11:48:16 AM11/28/04
to
I worked around this limitation with an ugly approach a while back (listview
but same principle):
http://groups.google.com/groups?hl=en&lr=&c2coff=1&q=listview+scrollbar+author%3AMoth&btnG=Search&meta=group%3Dmicrosoft.public.dotnet.framework.compactframework

Or write/use a custom list control.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Neville Lang" <neville@MAPS_ONnjlsoftware.com> wrote in message
news:eeqlEBW1...@TK2MSFTNGP14.phx.gbl...

nzpcmad

unread,
Nov 28, 2004, 2:16:14 PM11/28/04
to
The scrollbar on a Listview control is part of the non-client area.

To see scroll actions, create your own Listview:

public class myListView : System.Windows.Forms.ListView
{
protected override void WndProc (ref System.Windows.Forms.Message
m)
{
int WM_VSCROLL = 0x115;
int WM_HSCROLL = 0x114;

if (m.Msg == WM_VSCROLL)
{
// Some code here
break;
}

base.WndProc (ref m);
}
}

Then in "InitializeComponent()" change the line

this.listview = new System.Windows.Forms.ListView();

to

this.listview = new myListView ();

One question for the group?

Every time the form is changed, VisualStudio will overwrite
"InitializeComponent()" and the procedure will have to be re-edited.
Is there a way around this?

Many thanks

Daniel Moth

unread,
Nov 28, 2004, 2:22:28 PM11/28/04
to
> Every time the form is changed, VisualStudio will overwrite
> "InitializeComponent()" and the procedure will have to be re-edited.
> Is there a way around this?

Apart from not placing the code in there in the first place or not using the
designer, no.

BTW, did you try the code you just posted in a CF app?


"nzpcmad" <nzp...@yahoo.co.uk> wrote in message
news:fbd8029b.04112...@posting.google.com...

Neville Lang

unread,
Nov 28, 2004, 8:18:28 PM11/28/04
to
I tried your solution but found that both the ListBox and ListView WndProc
is not available for CF. That is why Daniel has asked you whether you
implemented this solution in CF.

Regards,
Neville Lang

"nzpcmad" <nzp...@yahoo.co.uk> wrote in message
news:fbd8029b.04112...@posting.google.com...

Neville Lang

unread,
Nov 28, 2004, 8:16:35 PM11/28/04
to
Daniel,

Thanks for the clue. I will try it out.

Regards,
Neville Lang


"Daniel Moth" <dmo...@hotmail.com> wrote in message
news:%238NGOoW...@tk2msftngp13.phx.gbl...

Neville Lang

unread,
Nov 29, 2004, 4:49:39 AM11/29/04
to
Daniel,

Just letting you know that your idea of simply overlaying a new vertical
scroll bar over the one that is created automatically on a ListBox does give
me the indication of when the user taps the scroll bar. Thanks for the clue
on how to get around this problem.

Regards,
Neville Lang

"Neville Lang" <neville@MAPS_ONnjlsoftware.com> wrote in message

news:uuV%23dFb1E...@TK2MSFTNGP15.phx.gbl...

Alex Feinman [MVP]

unread,
Nov 29, 2004, 3:26:16 PM11/29/04
to
In the sample here
http://www.alexfeinman.com/download.asp?doc=LBScrollAlways.zip I do exactly
that - overlay a scrollbar on top of the listbox control. You might find it
useful.

--
Alex Feinman
---
Visit http://www.opennetcf.org


"Neville Lang" <neville@MAPS_ONnjlsoftware.com> wrote in message

news:un5EJjf1...@tk2msftngp13.phx.gbl...

Neville Lang

unread,
Nov 29, 2004, 5:52:54 PM11/29/04
to
Alex,

Thank you for your response and file. It has given me some further ideas.

Regards,
Neville Lang

"Alex Feinman [MVP]" <publi...@alexfeinman.com> wrote in message
news:u4MGwGl1...@TK2MSFTNGP14.phx.gbl...

Neville Lang

unread,
Nov 29, 2004, 8:00:15 PM11/29/04
to
Alex,

Thank you for your response and file. It has given me some further ideas.

Regards,
Neville Lang

"Alex Feinman [MVP]" <publi...@alexfeinman.com> wrote in message
news:u4MGwGl1...@TK2MSFTNGP14.phx.gbl...

Reply all
Reply to author
Forward
0 new messages