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();
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
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With