Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET Forms
Hi,
I need a way to automatically scroll to a selected item in a list view. For example: There are 10 items in the list view and only the first 5 are visible. A function selects the 9th item and the list view should automatically scroll to the 9th item. I tried using the following code.
listView1.Items(8).Selected = True
listView1.Select()
listView1.SelectedItems(8).EnsureVisible
But it doesn't work. Please help
 
I've went through the code again and found out something new. It seems like the list view is actually selecting the item but it doesn't highlight the selected item in the list view and it also does not scroll to the selected item.
 
I tried refresh and update methods in the list view but it does not seem to be working. Please help
Posted 8-May-11 21:52pm
Edited 9-May-11 15:28pm
v4
Comments
SAKryukov at 9-May-11 2:58am
   
Tag it! Forms, WPF, what?!
--SA
obhasha07 at 9-May-11 3:30am
   
sorry mate the updated answer doesn't seem to be working. I don't know what's going on. The code I have given in my question worked when I run it the first time. But after a while it doesn't work. I've debugged the application and it even goes through every line. Please help!!!
Tarun.K.S at 9-May-11 6:36am
   
All I can say is weird!

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In WPF, you can use ScrollIntoView.
 
listView1.ScrollIntoView(listView1.Items[8]);
 
UPDATE: After your updated question, since its a WinForms application,
I tried in this way:
 
listView1.EnsureVisible(8);
Worked for me. Did it work for you?
  Permalink  
v2
Comments
obhasha07 at 9-May-11 3:03am
   
It's a windows forms application. So that doesn't help. But thanks anyway.
Tarun.K.S at 9-May-11 3:07am
   
I have updated the answer.

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



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 9 May 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100