如何滚动到列表视图中的选定项目 [英] How to scroll to a selected item in listview

查看:74
本文介绍了如何滚动到列表视图中的选定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要一种方法来自动滚动到列表视图中的选定项目。例如:列表视图中有10个项目,只有前5个可见。函数选择第9项,列表视图应自动滚动到第9项。我尝试使用以下代码。

 listView1.Items(8).Selected = True 
listView1.Select()
listView1.SelectedItems(8) .EnsureVisible



但它不起作用。请帮助



我再次检查了代码并找到了新的东西。看起来列表视图实际上是在选择项目,但它不会突出显示列表视图中的选定项目,也不会滚动到所选项目。



我在列表视图中尝试了刷新和更新方法,但它似乎没有用。请帮助

解决方案

在WPF中,您可以使用 ScrollIntoView



 listView1.ScrollIntoView(listView1.Items [8]); 





更新:更新后的问题,因为它是一个WinForms应用程序,

我试过这样:



 listView1.EnsureVisible(8); 



为我工作。它对你有用吗?


 ListView_ProgressStatus.Items [ListView_ProgressStatus.Items.Count  -   1  ] .EnsureVisible(); 


Hi,
I need a way to automatically scroll to a selected item in a list view. For example: There are 10 items in the list view and only the first 5 are visible. A function selects the 9th item and the list view should automatically scroll to the 9th item. I tried using the following code.

listView1.Items(8).Selected = True
listView1.Select()
listView1.SelectedItems(8).EnsureVisible


But it doesn't work. Please help

I've went through the code again and found out something new. It seems like the list view is actually selecting the item but it doesn't highlight the selected item in the list view and it also does not scroll to the selected item.

I tried refresh and update methods in the list view but it does not seem to be working. Please help

解决方案

In WPF, you can use ScrollIntoView.

listView1.ScrollIntoView(listView1.Items[8]);



UPDATE: After your updated question, since its a WinForms application,
I tried in this way:

listView1.EnsureVisible(8);


Worked for me. Did it work for you?


ListView_ProgressStatus.Items[ListView_ProgressStatus.Items.Count - 1].EnsureVisible();


这篇关于如何滚动到列表视图中的选定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆