Quantcast
Channel: Set ListView scroll position
Viewing all articles
Browse latest Browse all 11

Set ListView scroll position

$
0
0

Okay, I've got it working for my sorting scenario. I'm using a combination of GetScrollInfo and sending an LVM_SCROLL message to the ListView. I'm sure there's a more efficient way to do this, but this is what's currently working for me. This code below is running within my subclassed ListView control:

 

Code Snippet

    Private Const LVM_FIRST As Int32 = &H1000
    Private Const LVM_SCROLL As Int32 = LVM_FIRST + 20

    Structure SCROLLINFO
        Dim cbSize As Integer
        Dim fMask As Integer
        Dim nMin As Integer
        Dim nMax As Integer
        Dim nPage As Integer
        Dim nPos As Integer
        Dim nTrackPos As Integer
    End Structure

 

    Private Const SB_HORZ = 0
    Private Const SB_VERT = 1

    Private Const SIF_RANGE = &H1
    Private Const SIF_PAGE = &H2
    Private Const SIF_POS = &H4
    Private Const SIF_TRACKPOS = &H10
    Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)

 

    <DllImport("user32.dll")> _
    Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Int32, ByVal wParam As Int32, ByRef lParam As Int32) As Boolean
    End Function


    <DllImport("user32.dll")> _
    Private Shared Function GetScrollInfo(ByVal hWnd As IntPtr, ByVal n As Integer, ByRef lpScrollInfo As SCROLLINFO) As Integer
    End Function

 

    Public Shadows Sub Sort(ByVal ColumnIndex As Integer, ByVal CompareType As ListViewCompareType, ByVal Order As SortOrder)

 

' Get scroll position info

        Dim si As SCROLLINFO
        si.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(si)
        si.fMask = SIF_ALL


        GetScrollInfo(Handle, SB_HORZ, si)

 

' Not included: sorting logic, performed here

 

' Restore the scrollbar position

SendMessage(Handle, LVM_SCROLL, si.nPos, 0)

 

End Sub

 

 

 

 

 


Viewing all articles
Browse latest Browse all 11

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>