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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. getting text of selected item in listview

getting text of selected item in listview

Scheduled Pinned Locked Moved C / C++ / MFC
questioncsharpdotnetvisual-studiohelp
5 Posts 3 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.
  • T Offline
    T Offline
    Trucker
    wrote on last edited by
    #1

    Hi All, I have been trying to do this simple task for half a night and as simple as it sounds, I can't get it to work.:mad: I have a listview and I am trying to get the text of the selected item when user selects one (this is a single select listview). I've tried the following but none work:

    System::Void Form1::lv_files_SelectedIndexChanged(System::Object * sender, System::EventArgs * e){

    // Intellisense tells me that there is no '->Text'
    // after Item(0) even though when reading through
    // the .NET Framework, this sounded logical
    String\* sss = lv\_files->SelectedItems->Item(0)->Text;
    
    //Intellisense tells me this does not work either
    ListViewItem\* selectedFile = dynamic\_cast(e);
    String\* sss = selectedFile->Text;
    
    //...and many other unsuccessful ways which I already forgot
    

    }

    So how do I actually get the text of the selected item? Im tired, and passed the pissed off point so any help would be appreciated immensly:wtf: TraileR ParK LifE 4Ever >:{

    J 1 Reply Last reply
    0
    • T Trucker

      Hi All, I have been trying to do this simple task for half a night and as simple as it sounds, I can't get it to work.:mad: I have a listview and I am trying to get the text of the selected item when user selects one (this is a single select listview). I've tried the following but none work:

      System::Void Form1::lv_files_SelectedIndexChanged(System::Object * sender, System::EventArgs * e){

      // Intellisense tells me that there is no '->Text'
      // after Item(0) even though when reading through
      // the .NET Framework, this sounded logical
      String\* sss = lv\_files->SelectedItems->Item(0)->Text;
      
      //Intellisense tells me this does not work either
      ListViewItem\* selectedFile = dynamic\_cast(e);
      String\* sss = selectedFile->Text;
      
      //...and many other unsuccessful ways which I already forgot
      

      }

      So how do I actually get the text of the selected item? Im tired, and passed the pissed off point so any help would be appreciated immensly:wtf: TraileR ParK LifE 4Ever >:{

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      Try lv_files->SelectedItems[0]->Text -- jlr http://jlamas.blogspot.com/[^]

      T J 2 Replies Last reply
      0
      • J Jose Lamas Rios

        Try lv_files->SelectedItems[0]->Text -- jlr http://jlamas.blogspot.com/[^]

        T Offline
        T Offline
        Trucker
        wrote on last edited by
        #3

        It worked! Thanks a lot! ...And I've been trying all those complicated ways when this short line does it! :omg: Thanks again :) TraileR ParK LifE 4Ever >:{

        J 1 Reply Last reply
        0
        • T Trucker

          It worked! Thanks a lot! ...And I've been trying all those complicated ways when this short line does it! :omg: Thanks again :) TraileR ParK LifE 4Ever >:{

          J Offline
          J Offline
          Jose Lamas Rios
          wrote on last edited by
          #4

          gr8coaster329 wrote: ...And I've been trying all those complicated ways when this short line does it! Exactly my feelings whenever I see James Bond seducing yet another Bond girl. ;) gr8coaster329 wrote: Thanks again No problem. Glad to be of help :) -- "the name's Lamas, Jose Lamas" jlr http://jlamas.blogspot.com/[^]

          1 Reply Last reply
          0
          • J Jose Lamas Rios

            Try lv_files->SelectedItems[0]->Text -- jlr http://jlamas.blogspot.com/[^]

            J Offline
            J Offline
            Jordan C Atlas
            wrote on last edited by
            #5

            lv_files->SelectedItems[0]->Text

            Hi - I'm having this same issue. When I try the solution above, I get

            error C2227: left of '->Text' must point to class/struct/union

            (The intellisense also warns me that it won't work.) My code is: String* test = listView_Main->SelectedItems[0]->Text; Any suggestions? Thank you, --Jordan

            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