Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. ListView Item Selection Problem

ListView Item Selection Problem

Scheduled Pinned Locked Moved Managed C++/CLI
helpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bollwerj
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • B bollwerj

      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

      B Offline
      B Offline
      bollwerj
      wrote on last edited by
      #2

      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:

      H 1 Reply Last reply
      0
      • B bollwerj

        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:

        H Offline
        H Offline
        hyph3n
        wrote on last edited by
        #3

        Try listView1->FocusedItem->Text;

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups