How can I programmatically display the last item in a C# listview when there are vertical scrollbars? I've studied every method associated with listviews and can't find anything.
views:
1691answers:
6
A:
WPF or WinForms?
In WPF, you get the ListViewItem
and call BringIntoView
on it.
Daniel Earwicker
2009-03-05 20:34:53
+1
A:
WINFORMS:
Did you try setting the Selected value to TRUE in the last item in the Items collection of the ListView?
I think that doing this will focus on the last item... scrolling down if it is necesary. But I did't tryed myself.
EDIT: This will do the trick:
Me.ListView1.Items(Me.ListView1.Items.Count - 1).EnsureVisible()
Romias
2009-03-05 20:35:38
It set the focus but did not auto scroll. Any other ideas?
Auburnate
2009-03-05 20:40:08
+4
A:
It's not actually easy/possible to scroll the list view. You need to tell the item to make sure it's visible.
var items = listView.Items;
var last = items[items.Count-1];
last.EnsureVisible();
JaredPar
2009-03-05 20:37:12
This code works, but a horizontal bar shows up and conceals it on my CE device (due to the limited size). Any way to diable horizontal scroll bar?
Auburnate
2009-03-05 20:52:20
You need to take into account the vertical scrollbar width. Your columns should't use all the width of your ListView... save a little bit for the vertical scroll bar.
Romias
2009-03-05 21:01:15
+1
A:
this.listView1.Items[this.listView1.Items.Count - 1].EnsureVisible();
BFree
2009-03-05 20:37:31
A:
Hello,
This is a link to using a windows function to hide the horizontal and force vertical to be shown at all times:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/4aa4dade-53a2-4e2e-a8b4-b4980da1f39c/
JaredBroad
2009-09-15 21:53:11