我需要從列表視圖中刪除的項目,我要找的代碼會顯示一個消息框,確認,如果沒有選中的項,它會顯示一個錯誤消息框刪除項目在C#
這是我的代碼,它不工作:(
private void button2_Click(object sender, EventArgs e)
{
if (listView1.SelectedItems != null)
{
var confirmation = MessageBox.Show(
"Voulez vous vraiment supprimer les stagiaires séléctionnés?",
"Suppression", MessageBoxButtons.YesNo, MessageBoxIcon.Question
);
if (confirmation == DialogResult.Yes)
{
for (int i = 0; i < listView1.Items.Count; i++)
{
if (listView1.Items[i].Selected)
{
listView1.Items[i].Remove();
i--;
}
}
}
}
else
{
MessageBox.Show("aucin stagiaire selectionnes", "erreur",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
的錯誤是不刪除,但在messageboxs我有兩個messagesbox,ERREUR必須首先顯示確認之前。
您是否獲得在輸出窗口中的任何錯誤? – Thelonias 2013-03-22 14:03:07
你會得到什麼例外? – 2013-03-22 14:03:41
我沒有得到錯誤,也沒有例外,我實際上可以刪除項目,但是,錯誤是在messageboxs, 非常感謝:) – mabezat 2013-03-22 14:05:32