ListBox - How to detect a vertical scroll movement?

  • Thread starter Thread starter Neville Lang
  • Start date Start date
N

Neville Lang

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
 
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
 
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?

Cheers
Daniel
 
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
 
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
 
Alex,

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

Regards,
Neville Lang
 
Alex,

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

Regards,
Neville Lang
 
Back
Top