ListView Item index
How can we get the Dou开发者_Python百科bleClicked item (index) from a ListView?
private void listViewModels_MouseDoubleClick(object sender, MouseEventArgs e)
{
//This line doesn't work
int i = listViewModels.SelectedItem ();
string mdl_path=GetCurrentItemPath(i);
}
SelectedItem
isn't a function, try
ListViewItem item = listViewModels.SelectedItems[0];
What do you want to get?
If you want to get the selected index:
listBox1.SelectedIndex
If you want to get the ListViewItem
:
listBox1.Items[listBox1.SelectedIndex];
If you want to get the value of the selected item:
listBox1.SelectedValue;
If you want to get the text of the selected item:
listBox1.SelectedItem.ToString();
You'd generally want to use the ListView.GetItemAt(int x, int y) function:
void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
listView1.GetItemAt(e.X, e.Y);
}
精彩评论