visual-studio 以编程方式选择 Listview 的一行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4325572/
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
Select programmatically a row of a Listview
提问by masterchris_99
I don't get it to work to select a row of a listview at the beginning of my program.
我没有让它在我的程序开始时选择一行列表视图。
if (listView1.Items.Count > 0)
{
listView1.Items[0].Selected = true;
listView1.Items[0].Focused = true;
}
After running this snippet the first item is selected and focused.
运行此代码段后,第一个项目被选中并聚焦。
listView1.Items[0].Selected
true
listView1.Items[0].Focused
true
after clicking manually an item in the listview I can walk thru this list with
手动单击列表视图中的项目后,我可以浏览此列表
listView1.Items[newPosition].Selected = true;
regards
问候
回答by Bolu
set listView1.HideSelection=falseand listView1.Focus()
设置listView1.HideSelection=false和 listView1.Focus()

