0

我正在尝试通过对象发送者访问 listviewitem selectitem 文本属性。我该怎么做呢?

private void button1_Click(object sender, EventArgs e)
{
   ListViewItem LS = new ListViewItem(@"c:\windows\explorer.exe");
   ListViewItem LS1 = new ListViewItem(@"c:\windows\notepad.exe");
   listView1.Items.Add(LS);
   listView1.Items.Add(LS1);
}


private void listView1_Click(object sender, EventArgs e)
{
   // ???? how do I get listviewitem.text property here based on item selected 
   // ?? am i using the right eventhandler?
}
4

2 回答 2

1

您可以只使用 SelectedItems 属性:

if (listView1.SelectedItems.Count > 0)
    listView1.SelectedItems[0].Text // the text of the first selected item
于 2013-04-26T22:23:50.467 回答
0

只需使用它ListView本身即可访问它

myListView.SelectedItems[0].Text
于 2013-04-26T22:22:05.507 回答