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. C / C++ / MFC
  4. how can i get the current selected item from listcontrol.

how can i get the current selected item from listcontrol.

Scheduled Pinned Locked Moved C / C++ / MFC
question
17 Posts 4 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.
  • A Amit Agarrwal

    hi thanx but i want the text not the position of selected item. how can i get it. thanx

    P Offline
    P Offline
    Parthi_Appu
    wrote on last edited by
    #5

    Use CListCtrl::GetItemText(..) Refer, http://msdn2.microsoft.com/en-us/library/cbtzx5b1.aspx[^]

    A 1 Reply Last reply
    0
    • P Parthi_Appu

      Use CListCtrl::GetItemText(..) Refer, http://msdn2.microsoft.com/en-us/library/cbtzx5b1.aspx[^]

      A Offline
      A Offline
      Amit Agarrwal
      wrote on last edited by
      #6

      hi thanx i hav tried like this

      Position pos = m_listctrl.GetFirstSelectedItemPosition();
      str = m_listctrl.GetItemText(pos,1);

      then it gives me error

      error C2664: 'CString CListCtrl::GetItemText(int,int) const' : cannot convert parameter 1 from 'POSITION' to 'int'

      how to get the current index in int format. thanx

      P 2 Replies Last reply
      0
      • A Amit Agarrwal

        hi thanx i hav tried like this

        Position pos = m_listctrl.GetFirstSelectedItemPosition();
        str = m_listctrl.GetItemText(pos,1);

        then it gives me error

        error C2664: 'CString CListCtrl::GetItemText(int,int) const' : cannot convert parameter 1 from 'POSITION' to 'int'

        how to get the current index in int format. thanx

        P Offline
        P Offline
        Parthi_Appu
        wrote on last edited by
        #7

        You have to use GetNextSelectedItem(Pos)to get the item index, this will return the item index as 'int', use this 'int' value in GetItemText() and assign 0(zero) to subitem if you are not using the ListCtrl in Report View

        1 Reply Last reply
        0
        • A Amit Agarrwal

          hi thanx i hav tried like this

          Position pos = m_listctrl.GetFirstSelectedItemPosition();
          str = m_listctrl.GetItemText(pos,1);

          then it gives me error

          error C2664: 'CString CListCtrl::GetItemText(int,int) const' : cannot convert parameter 1 from 'POSITION' to 'int'

          how to get the current index in int format. thanx

          P Offline
          P Offline
          Parthi_Appu
          wrote on last edited by
          #8

          You have to use GetNextSelectedItem()to get the item index, this will return the item index as 'int', use this 'int' value in GetItemText() and assign 0(zero) to subitem if you are not using the ListCtrl in Report View

          A 2 Replies Last reply
          0
          • P Parthi_Appu

            You have to use GetNextSelectedItem()to get the item index, this will return the item index as 'int', use this 'int' value in GetItemText() and assign 0(zero) to subitem if you are not using the ListCtrl in Report View

            A Offline
            A Offline
            Amit Agarrwal
            wrote on last edited by
            #9

            hi thanx its working now but there is a problem.. i get the seleted string into the String variable and displaying the it in the MessageBox(). what is happing when i click on any item it shows the text but it shows the messagebox three time. why is this happening.......plz tell me thanx

            D 1 Reply Last reply
            0
            • P Parthi_Appu

              You have to use GetNextSelectedItem()to get the item index, this will return the item index as 'int', use this 'int' value in GetItemText() and assign 0(zero) to subitem if you are not using the ListCtrl in Report View

              A Offline
              A Offline
              Amit Agarrwal
              wrote on last edited by
              #10

              ok tell me which message i should pass for selecting item in listControl. for a simple list box there is lvnselchange message. but for a ListControl which one should i use. thanx

              1 Reply Last reply
              0
              • F FarPointer

                Try this CListCtrl::GetSelectionMark Regards, FarPointer Blog:FARPOINTER

                A Offline
                A Offline
                Amit Agarrwal
                wrote on last edited by
                #11

                which message i should pass for selecting item in listControl.

                F 1 Reply Last reply
                0
                • A Amit Agarrwal

                  how can i get the current selected item from listcontrol. thanx

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #12

                  If you are using MFC, use the CListCtrl::GetNextItem(-1, LVNI_SELECTED) method.


                  "The largest fire starts but with the smallest spark." - David Crow

                  "Judge not by the eye but by the heart." - Native American Proverb

                  A 1 Reply Last reply
                  0
                  • A Amit Agarrwal

                    hi thanx its working now but there is a problem.. i get the seleted string into the String variable and displaying the it in the MessageBox(). what is happing when i click on any item it shows the text but it shows the messagebox three time. why is this happening.......plz tell me thanx

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #13

                    aavesh wrote:

                    what is happing when i click on any item it shows the text but it shows the messagebox three time.

                    It sounds as though you are responding to the LVN_ITEMCHANGED message. When you select an item, more than one item has changed at that point. Study the NMLISTVIEW structure for details.


                    "The largest fire starts but with the smallest spark." - David Crow

                    "Judge not by the eye but by the heart." - Native American Proverb

                    1 Reply Last reply
                    0
                    • A Amit Agarrwal

                      which message i should pass for selecting item in listControl.

                      F Offline
                      F Offline
                      FarPointer
                      wrote on last edited by
                      #14

                      try this LVM_SETSELECTIONMARK


                      Regards, FarPointer Blog:FARPOINTER

                      1 Reply Last reply
                      0
                      • D David Crow

                        If you are using MFC, use the CListCtrl::GetNextItem(-1, LVNI_SELECTED) method.


                        "The largest fire starts but with the smallest spark." - David Crow

                        "Judge not by the eye but by the heart." - Native American Proverb

                        A Offline
                        A Offline
                        Amit Agarrwal
                        wrote on last edited by
                        #15

                        will this function return me the current item ..when i tried this function it give me error "LVS_SELECTED is uncdeclare identifier" thanx

                        D F 2 Replies Last reply
                        0
                        • A Amit Agarrwal

                          will this function return me the current item ..when i tried this function it give me error "LVS_SELECTED is uncdeclare identifier" thanx

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #16

                          It's considered good practice to read the documentation to confirm/verify what you read here. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listview/messages/lvm_getnextitem.asp[^]


                          "The largest fire starts but with the smallest spark." - David Crow

                          "Judge not by the eye but by the heart." - Native American Proverb

                          1 Reply Last reply
                          0
                          • A Amit Agarrwal

                            will this function return me the current item ..when i tried this function it give me error "LVS_SELECTED is uncdeclare identifier" thanx

                            F Offline
                            F Offline
                            FarPointer
                            wrote on last edited by
                            #17

                            This is not implemented :- LVS_SELECTED Regards, FarPointer Blog:FARPOINTER

                            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