views:

1691

answers:

6

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.

A: 

WPF or WinForms?

In WPF, you get the ListViewItem and call BringIntoView on it.

Daniel Earwicker
+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
It set the focus but did not auto scroll. Any other ideas?
Auburnate
+1  A: 

ListViewItem.EnsureVisible()

Michael Damatov
+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
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
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
+1  A: 
this.listView1.Items[this.listView1.Items.Count - 1].EnsureVisible();
BFree
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