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. Show selected rows in ListCtrl

Show selected rows in ListCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
12 Posts 5 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.
  • P Offline
    P Offline
    Pryabu
    wrote on last edited by
    #1

    How to show selected rows in ListCtrl. I tried with following code. But it is not working. LVITEM LvItem; memset(&LvItem,0,sizeof(LvItem)); LvItem.mask=LVIF_TEXT; LvItem.cchTextMax = 256; LvItem.iItem=0; LvItem.iSubItem=0; LvItem.pszText="1"; ::SendMessage(hwnd,LVM_INSERTITEM,0,(LONG)&LvItem); LvItem.pszText="2"; ::SendMessage(hwnd,LVM_INSERTITEM,1,(LONG)&LvItem); LvItem.pszText="3"; ::SendMessage(hwnd,LVM_INSERTITEM,3,(LONG)&LvItem); int nCount = m_ctrlList.GetItemCount(); int nRet = m_ctrlList.SetSelectionMark(1);

    _ C S 3 Replies Last reply
    0
    • P Pryabu

      How to show selected rows in ListCtrl. I tried with following code. But it is not working. LVITEM LvItem; memset(&LvItem,0,sizeof(LvItem)); LvItem.mask=LVIF_TEXT; LvItem.cchTextMax = 256; LvItem.iItem=0; LvItem.iSubItem=0; LvItem.pszText="1"; ::SendMessage(hwnd,LVM_INSERTITEM,0,(LONG)&LvItem); LvItem.pszText="2"; ::SendMessage(hwnd,LVM_INSERTITEM,1,(LONG)&LvItem); LvItem.pszText="3"; ::SendMessage(hwnd,LVM_INSERTITEM,3,(LONG)&LvItem); int nCount = m_ctrlList.GetItemCount(); int nRet = m_ctrlList.SetSelectionMark(1);

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      You could try m_ctrlList.SetItemState(1, LVIS_SELECTED, LVIS_SELECTED); if that is what you are asking.

      «_Superman_» I love work. It gives me something to do between weekends.

      P 1 Reply Last reply
      0
      • _ _Superman_

        You could try m_ctrlList.SetItemState(1, LVIS_SELECTED, LVIS_SELECTED); if that is what you are asking.

        «_Superman_» I love work. It gives me something to do between weekends.

        P Offline
        P Offline
        Pryabu
        wrote on last edited by
        #3

        m_ctrlList.SetItemState(1, LVIS_SELECTED, LVIS_SELECTED) function is not working

        _ D 2 Replies Last reply
        0
        • P Pryabu

          How to show selected rows in ListCtrl. I tried with following code. But it is not working. LVITEM LvItem; memset(&LvItem,0,sizeof(LvItem)); LvItem.mask=LVIF_TEXT; LvItem.cchTextMax = 256; LvItem.iItem=0; LvItem.iSubItem=0; LvItem.pszText="1"; ::SendMessage(hwnd,LVM_INSERTITEM,0,(LONG)&LvItem); LvItem.pszText="2"; ::SendMessage(hwnd,LVM_INSERTITEM,1,(LONG)&LvItem); LvItem.pszText="3"; ::SendMessage(hwnd,LVM_INSERTITEM,3,(LONG)&LvItem); int nCount = m_ctrlList.GetItemCount(); int nRet = m_ctrlList.SetSelectionMark(1);

          C Offline
          C Offline
          CDrone
          wrote on last edited by
          #4

          LVS_EX_FULLROWSELECT, I mean, use it with SetExtendedStyle().

          P 1 Reply Last reply
          0
          • C CDrone

            LVS_EX_FULLROWSELECT, I mean, use it with SetExtendedStyle().

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

            m_ctrlList.SetExtendedStyle(LVS_EX_FULLROWSELECT) is not working

            C 1 Reply Last reply
            0
            • P Pryabu

              m_ctrlList.SetItemState(1, LVIS_SELECTED, LVIS_SELECTED) function is not working

              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              Have you been able to insert items into the list control?

              «_Superman_» I love work. It gives me something to do between weekends.

              P 1 Reply Last reply
              0
              • _ _Superman_

                Have you been able to insert items into the list control?

                «_Superman_» I love work. It gives me something to do between weekends.

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

                Yes. I can able to add items in listctrl.

                P 1 Reply Last reply
                0
                • P Pryabu

                  m_ctrlList.SetExtendedStyle(LVS_EX_FULLROWSELECT) is not working

                  C Offline
                  C Offline
                  CDrone
                  wrote on last edited by
                  #8

                  Try like: DWORD dwStyle = m_ctrlList.GetExtendedStyle(); dwStyle |= LVS_EX_FULLROWSELECT; m_ctrlList.SetExtendedStyle(dwStyle);

                  1 Reply Last reply
                  0
                  • P Pryabu

                    Yes. I can able to add items in listctrl.

                    P Offline
                    P Offline
                    Pryabu
                    wrote on last edited by
                    #9

                    I enabled "Show Selection Always" property in resource editor.It is working.Thanks

                    1 Reply Last reply
                    0
                    • P Pryabu

                      How to show selected rows in ListCtrl. I tried with following code. But it is not working. LVITEM LvItem; memset(&LvItem,0,sizeof(LvItem)); LvItem.mask=LVIF_TEXT; LvItem.cchTextMax = 256; LvItem.iItem=0; LvItem.iSubItem=0; LvItem.pszText="1"; ::SendMessage(hwnd,LVM_INSERTITEM,0,(LONG)&LvItem); LvItem.pszText="2"; ::SendMessage(hwnd,LVM_INSERTITEM,1,(LONG)&LvItem); LvItem.pszText="3"; ::SendMessage(hwnd,LVM_INSERTITEM,3,(LONG)&LvItem); int nCount = m_ctrlList.GetItemCount(); int nRet = m_ctrlList.SetSelectionMark(1);

                      S Offline
                      S Offline
                      Sophiya Chen
                      wrote on last edited by
                      #10

                      it should set focuse on this ListCtrl,may be focuse problem. you can try!! :)

                      S 1 Reply Last reply
                      0
                      • S Sophiya Chen

                        it should set focuse on this ListCtrl,may be focuse problem. you can try!! :)

                        S Offline
                        S Offline
                        Sophiya Chen
                        wrote on last edited by
                        #11

                        and then SetItemState(...). if the focuse isn't on this control, it will not show the selected item.

                        1 Reply Last reply
                        0
                        • P Pryabu

                          m_ctrlList.SetItemState(1, LVIS_SELECTED, LVIS_SELECTED) function is not working

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

                          Roay wrote:

                          ...is not working

                          Which is anything but helpful. Did it produce a compiler/linker error? Did it throw an exception? Did it fire an assertion? What did it return?

                          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          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