Using a WndProc override

G

Guest

I've constructed a user control inherited from ListView so I can handle and
respond to scrolling events (to keep 2 listviews scrolling in sync).

My user control includes an Overrides of WndProc (I've attached the code at
the end of this mail). Is it possible to 'disable' this override until I need
it - it's just when I populate the ListViews this sub is called repeatadly.
What I'd like to do is populate the listviews and then 'enable' this override
to catch and trigger a scrolling event.

tia

Rob

Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
If m.Msg = WM_VSCROLL OrElse m.Msg = WM_MOUSEWHEEL Then
RaiseEvent VerticalScroll(Nothing, Nothing)
ElseIf m.Msg = WM_NOTIFY Then
Dim lParam As NMHDR = CType(m.GetLParam(GetType(NMHDR)), NMHDR)
If lParam.code = NM_HOVER Then
OnMouseHover(EventArgs.Empty)
End If
ElseIf m.Msg = LVM_ENSUREVISIBLE Then
RaiseEvent VerticalScroll(Nothing, Nothing)
End If
End Sub
 
R

rowe_newsgroups

Use a boolean variable or property.

Private MyBool as boolean = false

Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
if MyBool = true then
If m.Msg = WM_VSCROLL OrElse m.Msg = WM_MOUSEWHEEL Then
RaiseEvent VerticalScroll(Nothing, Nothing)
ElseIf m.Msg = WM_NOTIFY Then
Dim lParam As NMHDR = CType(m.GetLParam(GetType(NMHDR)),
NMHDR)
If lParam.code = NM_HOVER Then
OnMouseHover(EventArgs.Empty)
End If
ElseIf m.Msg = LVM_ENSUREVISIBLE Then
RaiseEvent VerticalScroll(Nothing, Nothing)
End If
end if
End Sub
 
G

Guest

Thanks - I was really wondering if there was an equivalent to the
Addhandler/Removehandler event approach to bypass the call to the sub
completely (until I was ready).
r
 
G

Guest

Thanks

I need the user control and use of wndproc to support the lack of a
scrolling event for the listview (after population). With the wndproc
override I'm trapping most of the user scroll actions and raising an event
which allows me to synchronise the scrolling between this listview and
another listview (using topitem) - to give me 'compare side by side' ala
Excel/Word type functionality.

It's not a big deal but whenever I do something (like add an item) to either
listivew then the wndproc override is triggered. I would like to surpress the
override until I need it (ie after I've populated both views).

I've got a beginupdate and endupdate settings around the population.

thanks again
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top