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. Listview selected item index ??

Listview selected item index ??

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabase
14 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 amitmistry_petlad

    How can I find the selected item index in listview??? suppose I have number of items in my list view and I have select five or six items randomly then how can I find the index of that selected items and subitems?

    "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

    N Offline
    N Offline
    Nelek
    wrote on last edited by
    #3

    I make it so:

    void CMyListView::OnItemchangedRulelist(NMHDR* pNMHDR, LRESULT* pResult)
    { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

    POSITION pos = m\_clcList.GetFirstSelectedItemPosition();
    while (pos)
    {	int nPos = m\_clcList.GetNextSelectedItem(pos);
    	//nPos is the inde**x** of the selected line,make what you want
    }
    
    \*pResult = 0;
    return;
    

    }

    Edit: I forgot to say that the list im using is one of the extended lists here in codeproject (i don't remember which one :doh:)

    Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

    A 1 Reply Last reply
    0
    • A Arman S

      Hi, Enumerate through the items and test each one;

      CListCtrl &ctrl = GetListCtrl();

      for (int j = 0; j < nCount; j ++)
      {
      if (ctrl.GetItemState(j, LVIS_SELECTED) == LVIS_SELECTED)) {
      // selected
      }
      }

      -- ===== Arman

      A Offline
      A Offline
      amitmistry_petlad
      wrote on last edited by
      #4

      Hi! Thanks actually i have try to do it in other way , following way, but in the array I got double values for one selected item now i will go through the steps you given. Actually i am working on win32(unicode). but its ok. Thanks

      "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

      1 Reply Last reply
      0
      • A Arman S

        Hi, Enumerate through the items and test each one;

        CListCtrl &ctrl = GetListCtrl();

        for (int j = 0; j < nCount; j ++)
        {
        if (ctrl.GetItemState(j, LVIS_SELECTED) == LVIS_SELECTED)) {
        // selected
        }
        }

        -- ===== Arman

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #5

        Arman Z. Sahakyan wrote:

        Enumerate through the items and test each one;

        Maybe a bit inefficient in large lists :) There's also CListCtrl::GetFirstSelectedItemPosition()/CListCtrl::GetNextSelectedItem() (LVM_GETNEXTITEM for non-MFC) too. Mark

        "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

        A A 2 Replies Last reply
        0
        • M Mark Salsbery

          Arman Z. Sahakyan wrote:

          Enumerate through the items and test each one;

          Maybe a bit inefficient in large lists :) There's also CListCtrl::GetFirstSelectedItemPosition()/CListCtrl::GetNextSelectedItem() (LVM_GETNEXTITEM for non-MFC) too. Mark

          "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

          A Offline
          A Offline
          Arman S
          wrote on last edited by
          #6

          Are you sure these APIs do not sequentially traverse all the elements by returning those with the specified style (e.g. selected ones)? I'm pretty sure it is so. :)

          -- ===== Arman

          M 1 Reply Last reply
          0
          • A Arman S

            Are you sure these APIs do not sequentially traverse all the elements by returning those with the specified style (e.g. selected ones)? I'm pretty sure it is so. :)

            -- ===== Arman

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #7

            Arman Z. Sahakyan wrote:

            Are you sure these APIs do not sequentially traverse all the elements by returning those with the specified style (e.g. selected ones)?

            Nope, I'm not sure! :) Never mind then! Mark

            "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

            1 Reply Last reply
            0
            • N Nelek

              I make it so:

              void CMyListView::OnItemchangedRulelist(NMHDR* pNMHDR, LRESULT* pResult)
              { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

              POSITION pos = m\_clcList.GetFirstSelectedItemPosition();
              while (pos)
              {	int nPos = m\_clcList.GetNextSelectedItem(pos);
              	//nPos is the inde**x** of the selected line,make what you want
              }
              
              \*pResult = 0;
              return;
              

              }

              Edit: I forgot to say that the list im using is one of the extended lists here in codeproject (i don't remember which one :doh:)

              Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

              A Offline
              A Offline
              amitmistry_petlad
              wrote on last edited by
              #8

              I need for win32(unicode). not for MFC

              "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

              N 1 Reply Last reply
              0
              • M Mark Salsbery

                Arman Z. Sahakyan wrote:

                Enumerate through the items and test each one;

                Maybe a bit inefficient in large lists :) There's also CListCtrl::GetFirstSelectedItemPosition()/CListCtrl::GetNextSelectedItem() (LVM_GETNEXTITEM for non-MFC) too. Mark

                "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                A Offline
                A Offline
                amitmistry_petlad
                wrote on last edited by
                #9

                Mark Salsbery wrote:

                GetFirstSelectedItemPosition()/

                What is Equivalent in win32????

                "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                M 1 Reply Last reply
                0
                • A amitmistry_petlad

                  Mark Salsbery wrote:

                  GetFirstSelectedItemPosition()/

                  What is Equivalent in win32????

                  "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                  M Offline
                  M Offline
                  Mark Salsbery
                  wrote on last edited by
                  #10

                  amitmistry_petlad wrote:

                  What is Equivalent in win32????

                  LVM_GETNEXTITEM

                  "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

                  1 Reply Last reply
                  0
                  • A amitmistry_petlad

                    I need for win32(unicode). not for MFC

                    "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                    N Offline
                    N Offline
                    Nelek
                    wrote on last edited by
                    #11

                    No problem, but next time say it before, we can not read minds :P ;)

                    Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

                    A 2 Replies Last reply
                    0
                    • N Nelek

                      No problem, but next time say it before, we can not read minds :P ;)

                      Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

                      A Offline
                      A Offline
                      amitmistry_petlad
                      wrote on last edited by
                      #12

                      :laugh: Thank you very much for your response. :rose:

                      "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                      1 Reply Last reply
                      0
                      • N Nelek

                        No problem, but next time say it before, we can not read minds :P ;)

                        Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

                        A Offline
                        A Offline
                        amitmistry_petlad
                        wrote on last edited by
                        #13

                        Sorry to ask you. what is M.D.V?

                        "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                        N 1 Reply Last reply
                        0
                        • A amitmistry_petlad

                          Sorry to ask you. what is M.D.V?

                          "Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India

                          N Offline
                          N Offline
                          Nelek
                          wrote on last edited by
                          #14

                          The first letters of my name :) hehehehe

                          Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?

                          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