CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2011
    Posts
    153

    Listview auto-scroll vertically

    I have this code:
    Code:
    Private Sub DragDropListView_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    
            If KeyItem Is Nothing Then
                If tmrLVScroll.Enabled Then tmrLVScroll.Enabled = False
                Return
            End If
    
            Cursor = Cursors.Hand
    
            Dim HeaderOffset As Integer
            If Me.View = Windows.Forms.View.Details Then HeaderOffset = Me.TopItem.GetBounds(ItemBoundsPortion.Entire).Top
    
            If e.Y <= HeaderOffset + Me.Font.Height / 1.5 Then
                intScrollDirection = 0
                tmrLVScroll.Enabled = True
            ElseIf e.Y >= Me.ClientSize.Height - Me.Font.Height / 1.5 Then
                intScrollDirection = 1
                tmrLVScroll.Enabled = True
            Else
                tmrLVScroll.Enabled = False
            End If
    
    
            Dim lastItemBottom As Integer = GetLastItemBottom(e)
            Dim PosX As Integer
    
            If Me.View = Windows.Forms.View.Details Then PosX = 0 Else PosX = e.X
            Dim itemOver As ListViewItem = Me.GetItemAt(PosX, lastItemBottom)
            If itemOver Is Nothing Then Return
            If itemOver.Index < _ReorderStartIndex Then
                If Me.Items.Count <= _ReorderStartIndex Then
                    itemOver = Nothing
                    Return
                Else
                    itemOver = Me.Items(_ReorderStartIndex)
                End If
            End If
    
            If e.Y < itemOver.Bounds.Top + itemOver.Bounds.Height / 2 Then
                Me.LineBefore = itemOver.Index
                Me.LineAfter = -1
            Else
                Me.LineBefore = -1
                Me.LineAfter = itemOver.Index
            End If
    
            Me.Invalidate()
    
        End Sub
    but I can't get it to auto scroll vertically for largeicon, smallicon, and tile listviews. Can someone shed some light on this. Also, is there a much simpler way of doing it?

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Listview auto-scroll vertically

    It looks like you are trying to do it the hard way.
    Have you tried just moving to the newly added item?
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Mar 2011
    Posts
    153

    Re: Listview auto-scroll vertically

    Yes, it won't move.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Listview auto-scroll vertically

    Try the EnsureVisible() method
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Mar 2011
    Posts
    153

    Re: Listview auto-scroll vertically

    I tried that to no avail. What I need to do is convert the horizontal lines that are drawn into to vertical ones.

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Listview auto-scroll vertically

    I'm not sure what you are saying, if you are talking about getting these views to display in a single column I know of no way to do so.

    Insurevisible will cause the list to scroll down to a point where the selected item is visible on screen.

    I have tested this and it worked fine.
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured