C# 更新新项目时如何在 WinForms ListView 控件中自动向下滚动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2014287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to auto scroll down in WinForms ListView control when update new item?
提问by monkey_boys
How to auto scroll down in ListView control when update new item?
更新新项目时如何在 ListView 控件中自动向下滚动?
I have tried
我试过了
listView1.Focus();
listView1.Items[listView1.Items.Count - 1].Selected = true;
but this not working.
但这不起作用。
采纳答案by Codesleuth
Try
尝试
listView1.Items[listView1.Items.Count - 1].EnsureVisible();
回答by Catalin DICU
maybe
也许
listView1.Items[listView1.Items.Count - 1].Selected = false;
listView1.Items[listView1.Items.Count - 1].Selected = true;
回答by Athena
Codesleuth's answer of calling EnsureVisible() on the last item in the list only worked for me when called during the forms OnShown() event.
Codesleuth 对列表中最后一项调用EnsureVisible() 的回答仅在Forms OnShown() 事件期间调用时才对我有用。
I tried doing it in the constructor, where I was populating my ListView, but nothing happened. Doing it during OnShown() worked a treat, however.
我尝试在构造函数中执行此操作,在该构造函数中填充我的 ListView,但什么也没发生。然而,在 OnShown() 期间这样做是一种享受。
Hope this helps.
希望这可以帮助。
回答by Kevin
where x is an int, of the item in the list you want to see
其中 x 是您要查看的列表中项目的整数
listView1.Items[x].Focus();
listView1.Items[x].Selected = true;
listView1.EnsureVisible(x);