尝试SelectedIndexChanged事件,而不是...指数位置是从零开始的,所以如果你有10个项目的指标将是0 - 9。如果你想0是那么行1只需添加一个。最后,当没有选择的项指数为-1
private void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (ListView1.SelectedIndex > -1)
{
// Add 1 so you have 1 - 10 instead of 0 - 9
int rowNumber = ListView1.SelectedIndex + 1;
// Your example says you want to delete the selected index
// so you still would want to use the selected index
ListView1.Items.RemoveAt(ListView1.SelectedIndex);
// After you remove the item, this method will fire again
// but the selected index will be -1 so none of this code will
// execute again.
}
}
请记住,此代码只支持一次选择一行。
希望这有助于...
你的意思是问如何获得索引? https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.selectedindices(v=vs.110).aspx – 2015-04-04 10:37:38
如果我选择项目我需要得到行号为这个选择 – 2015-04-04 10:57:05