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