对象发送者listviewitem .text属性

时间:2013-04-26 22:16:27

标签: c# .net winforms object sender

我试图通过对象发件人访问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?
}

2 个答案:

答案 0 :(得分:1)

您可以使用SelectedItems属性:

if (listView1.SelectedItems.Count > 0)
    listView1.SelectedItems[0].Text // the text of the first selected item

答案 1 :(得分:0)

只需使用ListView本身

即可访问它
myListView.SelectedItems[0].Text