Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
hi, can any one help me?? i want scroll to select point automatically:
here is my code

VB
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListView1.View = View.Details
        ListView1.FullRowSelect = True
        ListView1.GridLines = True
        ListView1.Columns.Add("ID", 40)
        For i As Integer = 0 To 20
            ListView1.Items.Add(i)

        Next

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListView1.Items(10).Selected = True
        ListView1.Select()
    End Sub
End Class


When i click on button1 it selected item 10 correctly, but the problem the scroll not go to that selected, please help me

Thanks in advance
Posted

1 solution

Use the EnsureVisible Method[^].
MSDN wrote:
Ensures that the item is visible within the control, scrolling the contents of the control, if necessary.

Add ListView1.Items(10).EnsureVisible() to your Button1_Click function.
VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ListView1.Items(10).Selected = True
    ListView1.Items(10).EnsureVisible()
    ListView1.Select()
End Sub
 
Share this answer
 
Comments
Long Bunly 11-Mar-12 10:59am    
you saved me !!!! thank you very very much :)
André Kraak 11-Mar-12 11:00am    
Your welcome.
ProEnggSoft 11-Mar-12 11:16am    
Good solution. My 5
fakhr 19-Jul-20 21:16pm    
ListView1.Items(10).EnsureVisible()

Works fine
thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900