dimanche 15 mars 2015

VC++ Windows Application ListView delete all selected items

I am beginner. I am trying to delete multiple selected items from the listView1 but it appears that after deleting one item, the list is not getting updated and hence the program is malfunctioning i.e. deleting some wrong items and skipping some right ones.


Here is my code:



private: System::Void delSelected_LinkClicked(System::Object^ sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^ e)
{
int count = listView1->SelectedItems->Count;
ListView::SelectedIndexCollection^ indexes = this->listView1->SelectedIndices;
System::Collections::IEnumerator^ myEnum1 = indexes->GetEnumerator();
MessageBox::Show(count.ToString(), "MessageBox Test", MessageBoxButtons::OK, MessageBoxIcon::Information);

while (myEnum1->MoveNext()) {
int index = safe_cast<int>(myEnum1->Current);
//MessageBox::Show(index.ToString()+". "+listView1->Items[index]->Text, "MessageBox Test", MessageBoxButtons::OK, MessageBoxIcon::Information);
listView1->Items->Remove(listView1->Items[index]);
}
}


I would like to know a way to update the list after one item is deleted or any other workaround.


Thanks.


Aucun commentaire:

Enregistrer un commentaire