Get selected Row in ListView
I have a Listener on the DoubleClick event in a ListView. I have also act开发者_高级运维ivated FullRowSelect.
So when I double-click a row, only the value in the first column appears. I also tried it directly with SelectedItems
.
Please help
Code:
private void lvRecipesPos_DoubleClick(object sender, EventArgs e)
{
String s = "";
foreach (ListViewItem item in lvRecipesPos.Items)
{
if (item.Selected == true)
{
s += item.Text.ToString();
}
}
MessageBox.Show(s);
}
1) The ListView
has a SelectedItems
collection, so you don't have to iterate all items and check if they're selected.
2) Item
has a SubItems
collection which holds the texts for all sub items
精彩评论