嘗試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