C# 查找列表视图的选定项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/325241/
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
Finding the selected item of list view
提问by instigator
I currently have a list view which has several rows of data and I have a contextmenustrip in C# .NET.
我目前有一个包含多行数据的列表视图,并且我在 C# .NET 中有一个上下文菜单。
What I am having problems with is when you click on the menu strip item I want to know which row has been selected.
我遇到的问题是,当您单击菜单条项时,我想知道已选择哪一行。
采纳答案by netadictos
To get selected rows as sindre says you do like this:
要像 sindre 所说的那样获取选定的行,您可以这样做:
foreach (ListViewItem item in lvFiles.SelectedItems)
{
....................................
}
lvFiles is the ListView.
lvFiles 是 ListView。
回答by sindre j
I really don't know what you mean here. Can you please explain your problem further or provide a code example?
我真的不知道你在这里是什么意思。您能否进一步解释您的问题或提供代码示例?
To get the selected row in a ListView you use the ListView.SelectedItems property. ListView.SelectedItems[0] will give you the first seleted item (as there can be more than one item selected)
要获取 ListView 中的选定行,请使用 ListView.SelectedItems 属性。ListView.SelectedItems[0] 会给你第一个选择的项目(因为可以选择多个项目)
回答by Sachin Gaur
To get the selected item of list view, try this:
要获取列表视图的选定项目,请尝试以下操作:
int index = 0;
if (this.myListView.SelectedItem.Count > 0)
index = this.myListView.SelectedIndices[0]
整数索引 = 0;
if (this.myListView.SelectedItem.Count > 0)
index = this.myListView.SelectedIndices[0]
This will give you the index of selected item in listview.
You may also refer this:
http://www.neowin.net/forum/index.php?showtopic=358458
这将为您提供列表视图中所选项目的索引。
你也可以参考这个:http:
//www.neowin.net/forum/index.php?showtopic=358458