ListView Item Selection Problem
-
Problem is in getting the selected item in a ListView. The view property is Details and MultiSelect is set to false. listView Here is the code I use: Void Form1::lvMain_SelectedIndexChanged(System::Object * sender, System::EventArgs * e) { ListView::SelectedListViewItemCollection* lvc = lvMain->get_SelectedItems(); IEnumerator* ie = lvc->GetEnumerator(); ie->MoveNext(); ListViewItem* lvi = __try_cast(ie->Current); . . . } The first time a selection is made in the listbox by clicking on an item, the selected item is returned in the SelectedListViewItemCollection which has a count of 1. without a problem. HOWEVER, the next time an item is clicked, the SelectedListViewItemCollection that is returned has a count of 0. Naturally, attempting to move the iterator causes an exception to be thrown. Does anyone know why nothing is returned in the SelectedListViewItemCollection when the selection is changed the second time??? Also, what is the solution??? Appreciate any help. John B
-
Problem is in getting the selected item in a ListView. The view property is Details and MultiSelect is set to false. listView Here is the code I use: Void Form1::lvMain_SelectedIndexChanged(System::Object * sender, System::EventArgs * e) { ListView::SelectedListViewItemCollection* lvc = lvMain->get_SelectedItems(); IEnumerator* ie = lvc->GetEnumerator(); ie->MoveNext(); ListViewItem* lvi = __try_cast(ie->Current); . . . } The first time a selection is made in the listbox by clicking on an item, the selected item is returned in the SelectedListViewItemCollection which has a count of 1. without a problem. HOWEVER, the next time an item is clicked, the SelectedListViewItemCollection that is returned has a count of 0. Naturally, attempting to move the iterator causes an exception to be thrown. Does anyone know why nothing is returned in the SelectedListViewItemCollection when the selection is changed the second time??? Also, what is the solution??? Appreciate any help. John B
Here is what seems to be happening: The first time an item is selected, the SelectedIndexChanged event is called and a SelectedListViewItemCollection is returned containing the selected item. Subsequent item selections seem to cause the SelectedIndexChanged event to be fired TWICE, the first time returning an empty collection but the second time returning selected items. Is this the way it is supposed to work??????? John B:confused:
-
Here is what seems to be happening: The first time an item is selected, the SelectedIndexChanged event is called and a SelectedListViewItemCollection is returned containing the selected item. Subsequent item selections seem to cause the SelectedIndexChanged event to be fired TWICE, the first time returning an empty collection but the second time returning selected items. Is this the way it is supposed to work??????? John B:confused: