Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh listview so that it shows the selectedindex?

I have a winforms listview with 200 items shown in a details listview.
50 items show at a time on the screen. I would like to hit a button and have the listview show the selected index # - for example #113.

The problem I'm having is that I can select index 113 but the listview will not show 113 at the top of the scroll range.

What do I have to do to get the listview to move to the selectindex?

UPDATE1:

The answer is to use EnsureVisible :

populateListView();
this.listView1.Items[113].Selected = true;
this.listView1.Items[113].EnsureVisible();   
like image 502
John M Avatar asked Nov 10 '11 16:11

John M


2 Answers

Did you try using yourList.SelectedItem.EnsureVisible

Use list.TopItem = list.Item[x] to have it scroll that item to the top (or attempt to)

http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.ensurevisible%28VS.90%29.aspx

like image 90
John Avatar answered Nov 12 '22 20:11

John


Ensure visible will make sure the item you define is visible in the window but not necessairly the top item in the ListView.

To make sure your selected item is the top item use the listView1.TopItem property

listView1.Items[113].Selected = true;
listView1.TopItem = listView1.SelectedItems[0];
like image 29
RobotMike Avatar answered Nov 12 '22 20:11

RobotMike