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.
当有垂直滚动条时,如何以编程方式显示C#listview中的最后一项?我研究了与listviews相关的每个方法,但找不到任何东西。
7 个解决方案
#1
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();
#2
this.listView1.Items[this.listView1.Items.Count - 1].EnsureVisible();
#3
ListViewItem.EnsureVisible()
#4
WINFORMS:
Did you try setting the Selected value to TRUE in the last item in the Items collection of the ListView?
您是否尝试在ListView的Items集合的最后一项中将Selected值设置为TRUE?
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()
#5
WPF or WinForms?
WPF还是WinForms?
In WPF, you get the ListViewItem
and call BringIntoView
on it.
在WPF中,您获取ListViewItem并在其上调用BringIntoView。
#6
This is a link to using a windows function to hide the horizontal and force vertical to be shown at all times:
这是一个使用Windows功能隐藏水平和强制垂直的链接,以便随时显示:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/4aa4dade-53a2-4e2e-a8b4-b4980da1f39c/
#7
The following hack will both select and show the last ListView item.
Not sure why this works but it works.
以下hack将选择并显示最后一个ListView项。不知道为什么这样有效,但它确实有效。
listview.SelectedIndices.Clear();
listview.FocusedItem = listview.Items[listview.Items.Count - 1];
listview.FocusedItem.Selected = true;
listview.BeginInvoke((MethodInvoker)delegate {
listview.FocusedItem.EnsureVisible();
});
Also, if you don't want a horizontal scroll bar to show, you need to resize ListView columns to fit the ListView's ClientArea
width before calling BeginInvoke
.
此外,如果您不想显示水平滚动条,则需要在调用BeginInvoke之前调整ListView列的大小以适合ListView的ClientArea宽度。
#1
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();
#2
this.listView1.Items[this.listView1.Items.Count - 1].EnsureVisible();
#3
ListViewItem.EnsureVisible()
#4
WINFORMS:
Did you try setting the Selected value to TRUE in the last item in the Items collection of the ListView?
您是否尝试在ListView的Items集合的最后一项中将Selected值设置为TRUE?
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()
#5
WPF or WinForms?
WPF还是WinForms?
In WPF, you get the ListViewItem
and call BringIntoView
on it.
在WPF中,您获取ListViewItem并在其上调用BringIntoView。
#6
This is a link to using a windows function to hide the horizontal and force vertical to be shown at all times:
这是一个使用Windows功能隐藏水平和强制垂直的链接,以便随时显示:
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/4aa4dade-53a2-4e2e-a8b4-b4980da1f39c/
#7
The following hack will both select and show the last ListView item.
Not sure why this works but it works.
以下hack将选择并显示最后一个ListView项。不知道为什么这样有效,但它确实有效。
listview.SelectedIndices.Clear();
listview.FocusedItem = listview.Items[listview.Items.Count - 1];
listview.FocusedItem.Selected = true;
listview.BeginInvoke((MethodInvoker)delegate {
listview.FocusedItem.EnsureVisible();
});
Also, if you don't want a horizontal scroll bar to show, you need to resize ListView columns to fit the ListView's ClientArea
width before calling BeginInvoke
.
此外,如果您不想显示水平滚动条,则需要在调用BeginInvoke之前调整ListView列的大小以适合ListView的ClientArea宽度。