Event Trap Listview vertical scrollbar - .net vb (framework 2.0) windows forms












0















I just can't seem to find a solution on the internet where I could event trap the Listview vertical scrollbar. Has someone found a solution that works in vb ; if so can you please post some code or reference to this . . .



(found solution see answer !)










share|improve this question

























  • You could (it looks like a hack, I know) override WndProc and wait for a WM_CTLCOLORLISTBOX message. Even if the MSDN description seems to point to something completely unrelated, this message is sent each time you scroll the ListBox (to paint the background). You can then check the TopIndex property and see whether the scrollbar has moved the top index of the ListBox. This message can be sent twice per scroll.

    – Jimi
    Dec 30 '18 at 0:23













  • May work with a listbox ; not sure if it could work with Listview. . .

    – BASit Bulbulia
    Dec 30 '18 at 0:30











  • Oops, I read ListBox for unknown reasons :) Nope, for a ListView you receive a WM_NOTIFY message.

    – Jimi
    Dec 30 '18 at 0:39








  • 2





    Should be able to convert something like this to VB I'm pretty sure: stackoverflow.com/questions/1851620/…

    – Nathan Champion
    Dec 30 '18 at 0:41






  • 2





    Or what @Nathan Champion posted (which requires a Custom Control). I forgot to mention that when you receive a WM_NOTIFY for a ListView scroll event, the Handle of the Control affected is provided in a NMHDR structure. The handle is referenced by the HWND hwndFrom member. You can use Marshal.PtrToStructure to retrieve the values from the Message lParam: (Dim messageHeader As nmHDR = Marshal.PtrToStructure(Of nmHDR)(m.LParam))

    – Jimi
    Dec 30 '18 at 1:21


















0















I just can't seem to find a solution on the internet where I could event trap the Listview vertical scrollbar. Has someone found a solution that works in vb ; if so can you please post some code or reference to this . . .



(found solution see answer !)










share|improve this question

























  • You could (it looks like a hack, I know) override WndProc and wait for a WM_CTLCOLORLISTBOX message. Even if the MSDN description seems to point to something completely unrelated, this message is sent each time you scroll the ListBox (to paint the background). You can then check the TopIndex property and see whether the scrollbar has moved the top index of the ListBox. This message can be sent twice per scroll.

    – Jimi
    Dec 30 '18 at 0:23













  • May work with a listbox ; not sure if it could work with Listview. . .

    – BASit Bulbulia
    Dec 30 '18 at 0:30











  • Oops, I read ListBox for unknown reasons :) Nope, for a ListView you receive a WM_NOTIFY message.

    – Jimi
    Dec 30 '18 at 0:39








  • 2





    Should be able to convert something like this to VB I'm pretty sure: stackoverflow.com/questions/1851620/…

    – Nathan Champion
    Dec 30 '18 at 0:41






  • 2





    Or what @Nathan Champion posted (which requires a Custom Control). I forgot to mention that when you receive a WM_NOTIFY for a ListView scroll event, the Handle of the Control affected is provided in a NMHDR structure. The handle is referenced by the HWND hwndFrom member. You can use Marshal.PtrToStructure to retrieve the values from the Message lParam: (Dim messageHeader As nmHDR = Marshal.PtrToStructure(Of nmHDR)(m.LParam))

    – Jimi
    Dec 30 '18 at 1:21
















0












0








0








I just can't seem to find a solution on the internet where I could event trap the Listview vertical scrollbar. Has someone found a solution that works in vb ; if so can you please post some code or reference to this . . .



(found solution see answer !)










share|improve this question
















I just can't seem to find a solution on the internet where I could event trap the Listview vertical scrollbar. Has someone found a solution that works in vb ; if so can you please post some code or reference to this . . .



(found solution see answer !)







.net vb.net






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 6:59







BASit Bulbulia

















asked Dec 29 '18 at 23:54









BASit BulbuliaBASit Bulbulia

559




559













  • You could (it looks like a hack, I know) override WndProc and wait for a WM_CTLCOLORLISTBOX message. Even if the MSDN description seems to point to something completely unrelated, this message is sent each time you scroll the ListBox (to paint the background). You can then check the TopIndex property and see whether the scrollbar has moved the top index of the ListBox. This message can be sent twice per scroll.

    – Jimi
    Dec 30 '18 at 0:23













  • May work with a listbox ; not sure if it could work with Listview. . .

    – BASit Bulbulia
    Dec 30 '18 at 0:30











  • Oops, I read ListBox for unknown reasons :) Nope, for a ListView you receive a WM_NOTIFY message.

    – Jimi
    Dec 30 '18 at 0:39








  • 2





    Should be able to convert something like this to VB I'm pretty sure: stackoverflow.com/questions/1851620/…

    – Nathan Champion
    Dec 30 '18 at 0:41






  • 2





    Or what @Nathan Champion posted (which requires a Custom Control). I forgot to mention that when you receive a WM_NOTIFY for a ListView scroll event, the Handle of the Control affected is provided in a NMHDR structure. The handle is referenced by the HWND hwndFrom member. You can use Marshal.PtrToStructure to retrieve the values from the Message lParam: (Dim messageHeader As nmHDR = Marshal.PtrToStructure(Of nmHDR)(m.LParam))

    – Jimi
    Dec 30 '18 at 1:21





















  • You could (it looks like a hack, I know) override WndProc and wait for a WM_CTLCOLORLISTBOX message. Even if the MSDN description seems to point to something completely unrelated, this message is sent each time you scroll the ListBox (to paint the background). You can then check the TopIndex property and see whether the scrollbar has moved the top index of the ListBox. This message can be sent twice per scroll.

    – Jimi
    Dec 30 '18 at 0:23













  • May work with a listbox ; not sure if it could work with Listview. . .

    – BASit Bulbulia
    Dec 30 '18 at 0:30











  • Oops, I read ListBox for unknown reasons :) Nope, for a ListView you receive a WM_NOTIFY message.

    – Jimi
    Dec 30 '18 at 0:39








  • 2





    Should be able to convert something like this to VB I'm pretty sure: stackoverflow.com/questions/1851620/…

    – Nathan Champion
    Dec 30 '18 at 0:41






  • 2





    Or what @Nathan Champion posted (which requires a Custom Control). I forgot to mention that when you receive a WM_NOTIFY for a ListView scroll event, the Handle of the Control affected is provided in a NMHDR structure. The handle is referenced by the HWND hwndFrom member. You can use Marshal.PtrToStructure to retrieve the values from the Message lParam: (Dim messageHeader As nmHDR = Marshal.PtrToStructure(Of nmHDR)(m.LParam))

    – Jimi
    Dec 30 '18 at 1:21



















You could (it looks like a hack, I know) override WndProc and wait for a WM_CTLCOLORLISTBOX message. Even if the MSDN description seems to point to something completely unrelated, this message is sent each time you scroll the ListBox (to paint the background). You can then check the TopIndex property and see whether the scrollbar has moved the top index of the ListBox. This message can be sent twice per scroll.

– Jimi
Dec 30 '18 at 0:23







You could (it looks like a hack, I know) override WndProc and wait for a WM_CTLCOLORLISTBOX message. Even if the MSDN description seems to point to something completely unrelated, this message is sent each time you scroll the ListBox (to paint the background). You can then check the TopIndex property and see whether the scrollbar has moved the top index of the ListBox. This message can be sent twice per scroll.

– Jimi
Dec 30 '18 at 0:23















May work with a listbox ; not sure if it could work with Listview. . .

– BASit Bulbulia
Dec 30 '18 at 0:30





May work with a listbox ; not sure if it could work with Listview. . .

– BASit Bulbulia
Dec 30 '18 at 0:30













Oops, I read ListBox for unknown reasons :) Nope, for a ListView you receive a WM_NOTIFY message.

– Jimi
Dec 30 '18 at 0:39







Oops, I read ListBox for unknown reasons :) Nope, for a ListView you receive a WM_NOTIFY message.

– Jimi
Dec 30 '18 at 0:39






2




2





Should be able to convert something like this to VB I'm pretty sure: stackoverflow.com/questions/1851620/…

– Nathan Champion
Dec 30 '18 at 0:41





Should be able to convert something like this to VB I'm pretty sure: stackoverflow.com/questions/1851620/…

– Nathan Champion
Dec 30 '18 at 0:41




2




2





Or what @Nathan Champion posted (which requires a Custom Control). I forgot to mention that when you receive a WM_NOTIFY for a ListView scroll event, the Handle of the Control affected is provided in a NMHDR structure. The handle is referenced by the HWND hwndFrom member. You can use Marshal.PtrToStructure to retrieve the values from the Message lParam: (Dim messageHeader As nmHDR = Marshal.PtrToStructure(Of nmHDR)(m.LParam))

– Jimi
Dec 30 '18 at 1:21







Or what @Nathan Champion posted (which requires a Custom Control). I forgot to mention that when you receive a WM_NOTIFY for a ListView scroll event, the Handle of the Control affected is provided in a NMHDR structure. The handle is referenced by the HWND hwndFrom member. You can use Marshal.PtrToStructure to retrieve the values from the Message lParam: (Dim messageHeader As nmHDR = Marshal.PtrToStructure(Of nmHDR)(m.LParam))

– Jimi
Dec 30 '18 at 1:21














1 Answer
1






active

oldest

votes


















0














After much research I finally came up with a .net vb solution :-)



Public Class Form1
Public Class ControlScrollListener
Inherits NativeWindow
Implements IDisposable

' Event
Public Event Scroll As ScrollEventHandler
Public Delegate Sub ScrollEventHandler(ByVal sender As Object, ByVal e As EventArgs)

' Flag: Has Dispose already been called?
Private Disposed As Boolean

' Windows message for Horizontal Scroll
Private Const WM_HSCROLL As UInteger = &H114

' Windows message for Vertical Scroll
Private Const WM_VSCROLL As UInteger = &H115

' Windows message for mouse wheel
Private Const WM_MOUSEWHEEL As UInteger = &H20A

' The control object
Private sender As Control

''' <summary>
''' Constructor
''' </summary>
Public Sub New()
sender = Nothing
End Sub

''' <summary>
''' Constructor
''' </summary>
''' <param name="control">The control object</param>
Public Sub New(ByVal control As Control)
sender = control
AssignHandle(sender.Handle)
End Sub

''' <summary>
''' Public implementation of Dispose pattern callable by consumers.
''' </summary>
Public Sub Dispose() Implements IDisposable.Dispose
Dispose(True)
GC.SuppressFinalize(Me)
End Sub

''' <summary>
''' Invokes the default window procedure associated with this window
''' </summary>
''' <param name="m">A Message that is associated with the current Windows message.</param>
''' <remarks>This method is called when a window message is sent to the handle of the window</remarks>
Protected Overrides Sub WndProc(ByRef m As Message)
HandleControlScroll(m)
MyBase.WndProc(m)
End Sub

''' <summary>
''' Protected implementation of Dispose pattern.
''' </summary>
''' <param name="disposing">The boolean value for disposing object</param>
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Disposed Then Return

If disposing Then
' Free any other managed objects here.
sender = Nothing
End If

' Free any unmanaged objects here.
ReleaseHandle()
Disposed = True
End Sub

''' <summary>
''' Handle control scroll
''' </summary>
''' <param name="m">A Message that is associated with the current Windows message.</param>
Private Sub HandleControlScroll(ByVal m As Message)
If m.Msg = WM_HSCROLL Or m.Msg = WM_VSCROLL Or m.Msg = WM_MOUSEWHEEL Then


If Not sender Is Nothing Then
RaiseEvent Scroll(sender, New EventArgs())

End If
End If
End Sub
End Class

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load


'Creating the list items
Dim ListItem1 As ListViewItem
ListItem1 = ListView1.Items.Add("Item 1")

Dim ListItem2 As ListViewItem
ListItem2 = ListView1.Items.Add("Item 2")

Dim ListItem3 As ListViewItem
ListItem3 = ListView1.Items.Add("Item 3")

Dim ListItem4 As ListViewItem
ListItem4 = ListView1.Items.Add("Item 4")


ListView1.View = View.SmallIcon

Dim scrollListener As New ControlScrollListener(ListView1)
AddHandler scrollListener.Scroll, AddressOf listview1_scroll


End Sub

Private Sub listview1_scroll(sender As Object, e As EventArgs)

'here you capture the scroll and do something with it !
'example: msgbox("Scroll happen !")

End Sub

End Class





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53974262%2fevent-trap-listview-vertical-scrollbar-net-vb-framework-2-0-windows-forms%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    After much research I finally came up with a .net vb solution :-)



    Public Class Form1
    Public Class ControlScrollListener
    Inherits NativeWindow
    Implements IDisposable

    ' Event
    Public Event Scroll As ScrollEventHandler
    Public Delegate Sub ScrollEventHandler(ByVal sender As Object, ByVal e As EventArgs)

    ' Flag: Has Dispose already been called?
    Private Disposed As Boolean

    ' Windows message for Horizontal Scroll
    Private Const WM_HSCROLL As UInteger = &H114

    ' Windows message for Vertical Scroll
    Private Const WM_VSCROLL As UInteger = &H115

    ' Windows message for mouse wheel
    Private Const WM_MOUSEWHEEL As UInteger = &H20A

    ' The control object
    Private sender As Control

    ''' <summary>
    ''' Constructor
    ''' </summary>
    Public Sub New()
    sender = Nothing
    End Sub

    ''' <summary>
    ''' Constructor
    ''' </summary>
    ''' <param name="control">The control object</param>
    Public Sub New(ByVal control As Control)
    sender = control
    AssignHandle(sender.Handle)
    End Sub

    ''' <summary>
    ''' Public implementation of Dispose pattern callable by consumers.
    ''' </summary>
    Public Sub Dispose() Implements IDisposable.Dispose
    Dispose(True)
    GC.SuppressFinalize(Me)
    End Sub

    ''' <summary>
    ''' Invokes the default window procedure associated with this window
    ''' </summary>
    ''' <param name="m">A Message that is associated with the current Windows message.</param>
    ''' <remarks>This method is called when a window message is sent to the handle of the window</remarks>
    Protected Overrides Sub WndProc(ByRef m As Message)
    HandleControlScroll(m)
    MyBase.WndProc(m)
    End Sub

    ''' <summary>
    ''' Protected implementation of Dispose pattern.
    ''' </summary>
    ''' <param name="disposing">The boolean value for disposing object</param>
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
    If Disposed Then Return

    If disposing Then
    ' Free any other managed objects here.
    sender = Nothing
    End If

    ' Free any unmanaged objects here.
    ReleaseHandle()
    Disposed = True
    End Sub

    ''' <summary>
    ''' Handle control scroll
    ''' </summary>
    ''' <param name="m">A Message that is associated with the current Windows message.</param>
    Private Sub HandleControlScroll(ByVal m As Message)
    If m.Msg = WM_HSCROLL Or m.Msg = WM_VSCROLL Or m.Msg = WM_MOUSEWHEEL Then


    If Not sender Is Nothing Then
    RaiseEvent Scroll(sender, New EventArgs())

    End If
    End If
    End Sub
    End Class

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load


    'Creating the list items
    Dim ListItem1 As ListViewItem
    ListItem1 = ListView1.Items.Add("Item 1")

    Dim ListItem2 As ListViewItem
    ListItem2 = ListView1.Items.Add("Item 2")

    Dim ListItem3 As ListViewItem
    ListItem3 = ListView1.Items.Add("Item 3")

    Dim ListItem4 As ListViewItem
    ListItem4 = ListView1.Items.Add("Item 4")


    ListView1.View = View.SmallIcon

    Dim scrollListener As New ControlScrollListener(ListView1)
    AddHandler scrollListener.Scroll, AddressOf listview1_scroll


    End Sub

    Private Sub listview1_scroll(sender As Object, e As EventArgs)

    'here you capture the scroll and do something with it !
    'example: msgbox("Scroll happen !")

    End Sub

    End Class





    share|improve this answer




























      0














      After much research I finally came up with a .net vb solution :-)



      Public Class Form1
      Public Class ControlScrollListener
      Inherits NativeWindow
      Implements IDisposable

      ' Event
      Public Event Scroll As ScrollEventHandler
      Public Delegate Sub ScrollEventHandler(ByVal sender As Object, ByVal e As EventArgs)

      ' Flag: Has Dispose already been called?
      Private Disposed As Boolean

      ' Windows message for Horizontal Scroll
      Private Const WM_HSCROLL As UInteger = &H114

      ' Windows message for Vertical Scroll
      Private Const WM_VSCROLL As UInteger = &H115

      ' Windows message for mouse wheel
      Private Const WM_MOUSEWHEEL As UInteger = &H20A

      ' The control object
      Private sender As Control

      ''' <summary>
      ''' Constructor
      ''' </summary>
      Public Sub New()
      sender = Nothing
      End Sub

      ''' <summary>
      ''' Constructor
      ''' </summary>
      ''' <param name="control">The control object</param>
      Public Sub New(ByVal control As Control)
      sender = control
      AssignHandle(sender.Handle)
      End Sub

      ''' <summary>
      ''' Public implementation of Dispose pattern callable by consumers.
      ''' </summary>
      Public Sub Dispose() Implements IDisposable.Dispose
      Dispose(True)
      GC.SuppressFinalize(Me)
      End Sub

      ''' <summary>
      ''' Invokes the default window procedure associated with this window
      ''' </summary>
      ''' <param name="m">A Message that is associated with the current Windows message.</param>
      ''' <remarks>This method is called when a window message is sent to the handle of the window</remarks>
      Protected Overrides Sub WndProc(ByRef m As Message)
      HandleControlScroll(m)
      MyBase.WndProc(m)
      End Sub

      ''' <summary>
      ''' Protected implementation of Dispose pattern.
      ''' </summary>
      ''' <param name="disposing">The boolean value for disposing object</param>
      Protected Overridable Sub Dispose(ByVal disposing As Boolean)
      If Disposed Then Return

      If disposing Then
      ' Free any other managed objects here.
      sender = Nothing
      End If

      ' Free any unmanaged objects here.
      ReleaseHandle()
      Disposed = True
      End Sub

      ''' <summary>
      ''' Handle control scroll
      ''' </summary>
      ''' <param name="m">A Message that is associated with the current Windows message.</param>
      Private Sub HandleControlScroll(ByVal m As Message)
      If m.Msg = WM_HSCROLL Or m.Msg = WM_VSCROLL Or m.Msg = WM_MOUSEWHEEL Then


      If Not sender Is Nothing Then
      RaiseEvent Scroll(sender, New EventArgs())

      End If
      End If
      End Sub
      End Class

      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load


      'Creating the list items
      Dim ListItem1 As ListViewItem
      ListItem1 = ListView1.Items.Add("Item 1")

      Dim ListItem2 As ListViewItem
      ListItem2 = ListView1.Items.Add("Item 2")

      Dim ListItem3 As ListViewItem
      ListItem3 = ListView1.Items.Add("Item 3")

      Dim ListItem4 As ListViewItem
      ListItem4 = ListView1.Items.Add("Item 4")


      ListView1.View = View.SmallIcon

      Dim scrollListener As New ControlScrollListener(ListView1)
      AddHandler scrollListener.Scroll, AddressOf listview1_scroll


      End Sub

      Private Sub listview1_scroll(sender As Object, e As EventArgs)

      'here you capture the scroll and do something with it !
      'example: msgbox("Scroll happen !")

      End Sub

      End Class





      share|improve this answer


























        0












        0








        0







        After much research I finally came up with a .net vb solution :-)



        Public Class Form1
        Public Class ControlScrollListener
        Inherits NativeWindow
        Implements IDisposable

        ' Event
        Public Event Scroll As ScrollEventHandler
        Public Delegate Sub ScrollEventHandler(ByVal sender As Object, ByVal e As EventArgs)

        ' Flag: Has Dispose already been called?
        Private Disposed As Boolean

        ' Windows message for Horizontal Scroll
        Private Const WM_HSCROLL As UInteger = &H114

        ' Windows message for Vertical Scroll
        Private Const WM_VSCROLL As UInteger = &H115

        ' Windows message for mouse wheel
        Private Const WM_MOUSEWHEEL As UInteger = &H20A

        ' The control object
        Private sender As Control

        ''' <summary>
        ''' Constructor
        ''' </summary>
        Public Sub New()
        sender = Nothing
        End Sub

        ''' <summary>
        ''' Constructor
        ''' </summary>
        ''' <param name="control">The control object</param>
        Public Sub New(ByVal control As Control)
        sender = control
        AssignHandle(sender.Handle)
        End Sub

        ''' <summary>
        ''' Public implementation of Dispose pattern callable by consumers.
        ''' </summary>
        Public Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        GC.SuppressFinalize(Me)
        End Sub

        ''' <summary>
        ''' Invokes the default window procedure associated with this window
        ''' </summary>
        ''' <param name="m">A Message that is associated with the current Windows message.</param>
        ''' <remarks>This method is called when a window message is sent to the handle of the window</remarks>
        Protected Overrides Sub WndProc(ByRef m As Message)
        HandleControlScroll(m)
        MyBase.WndProc(m)
        End Sub

        ''' <summary>
        ''' Protected implementation of Dispose pattern.
        ''' </summary>
        ''' <param name="disposing">The boolean value for disposing object</param>
        Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Disposed Then Return

        If disposing Then
        ' Free any other managed objects here.
        sender = Nothing
        End If

        ' Free any unmanaged objects here.
        ReleaseHandle()
        Disposed = True
        End Sub

        ''' <summary>
        ''' Handle control scroll
        ''' </summary>
        ''' <param name="m">A Message that is associated with the current Windows message.</param>
        Private Sub HandleControlScroll(ByVal m As Message)
        If m.Msg = WM_HSCROLL Or m.Msg = WM_VSCROLL Or m.Msg = WM_MOUSEWHEEL Then


        If Not sender Is Nothing Then
        RaiseEvent Scroll(sender, New EventArgs())

        End If
        End If
        End Sub
        End Class

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load


        'Creating the list items
        Dim ListItem1 As ListViewItem
        ListItem1 = ListView1.Items.Add("Item 1")

        Dim ListItem2 As ListViewItem
        ListItem2 = ListView1.Items.Add("Item 2")

        Dim ListItem3 As ListViewItem
        ListItem3 = ListView1.Items.Add("Item 3")

        Dim ListItem4 As ListViewItem
        ListItem4 = ListView1.Items.Add("Item 4")


        ListView1.View = View.SmallIcon

        Dim scrollListener As New ControlScrollListener(ListView1)
        AddHandler scrollListener.Scroll, AddressOf listview1_scroll


        End Sub

        Private Sub listview1_scroll(sender As Object, e As EventArgs)

        'here you capture the scroll and do something with it !
        'example: msgbox("Scroll happen !")

        End Sub

        End Class





        share|improve this answer













        After much research I finally came up with a .net vb solution :-)



        Public Class Form1
        Public Class ControlScrollListener
        Inherits NativeWindow
        Implements IDisposable

        ' Event
        Public Event Scroll As ScrollEventHandler
        Public Delegate Sub ScrollEventHandler(ByVal sender As Object, ByVal e As EventArgs)

        ' Flag: Has Dispose already been called?
        Private Disposed As Boolean

        ' Windows message for Horizontal Scroll
        Private Const WM_HSCROLL As UInteger = &H114

        ' Windows message for Vertical Scroll
        Private Const WM_VSCROLL As UInteger = &H115

        ' Windows message for mouse wheel
        Private Const WM_MOUSEWHEEL As UInteger = &H20A

        ' The control object
        Private sender As Control

        ''' <summary>
        ''' Constructor
        ''' </summary>
        Public Sub New()
        sender = Nothing
        End Sub

        ''' <summary>
        ''' Constructor
        ''' </summary>
        ''' <param name="control">The control object</param>
        Public Sub New(ByVal control As Control)
        sender = control
        AssignHandle(sender.Handle)
        End Sub

        ''' <summary>
        ''' Public implementation of Dispose pattern callable by consumers.
        ''' </summary>
        Public Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        GC.SuppressFinalize(Me)
        End Sub

        ''' <summary>
        ''' Invokes the default window procedure associated with this window
        ''' </summary>
        ''' <param name="m">A Message that is associated with the current Windows message.</param>
        ''' <remarks>This method is called when a window message is sent to the handle of the window</remarks>
        Protected Overrides Sub WndProc(ByRef m As Message)
        HandleControlScroll(m)
        MyBase.WndProc(m)
        End Sub

        ''' <summary>
        ''' Protected implementation of Dispose pattern.
        ''' </summary>
        ''' <param name="disposing">The boolean value for disposing object</param>
        Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Disposed Then Return

        If disposing Then
        ' Free any other managed objects here.
        sender = Nothing
        End If

        ' Free any unmanaged objects here.
        ReleaseHandle()
        Disposed = True
        End Sub

        ''' <summary>
        ''' Handle control scroll
        ''' </summary>
        ''' <param name="m">A Message that is associated with the current Windows message.</param>
        Private Sub HandleControlScroll(ByVal m As Message)
        If m.Msg = WM_HSCROLL Or m.Msg = WM_VSCROLL Or m.Msg = WM_MOUSEWHEEL Then


        If Not sender Is Nothing Then
        RaiseEvent Scroll(sender, New EventArgs())

        End If
        End If
        End Sub
        End Class

        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load


        'Creating the list items
        Dim ListItem1 As ListViewItem
        ListItem1 = ListView1.Items.Add("Item 1")

        Dim ListItem2 As ListViewItem
        ListItem2 = ListView1.Items.Add("Item 2")

        Dim ListItem3 As ListViewItem
        ListItem3 = ListView1.Items.Add("Item 3")

        Dim ListItem4 As ListViewItem
        ListItem4 = ListView1.Items.Add("Item 4")


        ListView1.View = View.SmallIcon

        Dim scrollListener As New ControlScrollListener(ListView1)
        AddHandler scrollListener.Scroll, AddressOf listview1_scroll


        End Sub

        Private Sub listview1_scroll(sender As Object, e As EventArgs)

        'here you capture the scroll and do something with it !
        'example: msgbox("Scroll happen !")

        End Sub

        End Class






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 7:04









        BASit BulbuliaBASit Bulbulia

        559




        559
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53974262%2fevent-trap-listview-vertical-scrollbar-net-vb-framework-2-0-windows-forms%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            Npm cannot find a required file even through it is in the searched directory