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. How to delete entire row in CListCtrl?

How to delete entire row in CListCtrl?

Scheduled Pinned Locked Moved C / C++ / MFC
databasetutorialquestion
6 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.
  • J Offline
    J Offline
    julych
    wrote on last edited by
    #1

    How to delete entire row in CListCtrl? I can't find a function which returns the index of the selected row(item).

    R G 2 Replies Last reply
    0
    • J julych

      How to delete entire row in CListCtrl? I can't find a function which returns the index of the selected row(item).

      R Offline
      R Offline
      Renjith Ramachandran
      wrote on last edited by
      #2

      use member function DeleteAllItems(); simple ;) CodeTheDreams();

      J 1 Reply Last reply
      0
      • R Renjith Ramachandran

        use member function DeleteAllItems(); simple ;) CodeTheDreams();

        J Offline
        J Offline
        julych
        wrote on last edited by
        #3

        But it deletes all the items(rows)!!! I want to delete just a single row:-(

        J H 2 Replies Last reply
        0
        • J julych

          But it deletes all the items(rows)!!! I want to delete just a single row:-(

          J Offline
          J Offline
          jmkhael
          wrote on last edited by
          #4

          CListCtrl::DeleteItem Papa while (TRUE) Papa.WillLove ( Bebe ) ;

          1 Reply Last reply
          0
          • J julych

            How to delete entire row in CListCtrl? I can't find a function which returns the index of the selected row(item).

            G Offline
            G Offline
            G Steudtel
            wrote on last edited by
            #5

            Hi, if you need to find the selected item in a listcontrol, there is no function, to do it. In your code for deleting a row you may use this to find the desired index long lx; LV_ITEM lvItem; lvItem.iItem = 0; lvItem.iSubItem = 0; lvItem.mask = 0; lvItem.state = 0; lvItem.stateMask = 0; if(m_VarForListCtrl.GetSelectedCount() != 1 ) return; // if none or more than one are selected bail out int iItem = m_VarForListCtrl.GetTopIndex(); int iMax = m_VarForListCtrl.GetCountPerPage(); for( int i = iItem; i < ( iItem + iMax ); i++) { lvItem.iItem = i; lvItem.iSubItem = 0; lvItem.mask = LVIF_STATE; lvItem.state = LVIS_SELECTED; lvItem.stateMask = LVIS_SELECTED; if( !m_VarForListCtrl.GetItem(&lvItem) ) { return; // if item can't be read, do nothing } if( lvItem.state ) break;// found item } if( !lvItem.state ) return; // no item found // lvItem.iItem now has the index of the selected row m_VarForListCtrl.DeleteItem(lvItem.iItem); This code wil find only the selected item if it's visible. You must adapt the code, if you are searching the whole list. Was it this you were looking for? G. Steudtel

            1 Reply Last reply
            0
            • J julych

              But it deletes all the items(rows)!!! I want to delete just a single row:-(

              H Offline
              H Offline
              Hari Krishnan Noida
              wrote on last edited by
              #6

              Hi, You do the following, m_LCtrlPtr->DeleteItem(m_LCtrlPtr->GetSelectionMark()); This will delete the currently selected item in the list control. GetSelectionMark() is to retrieve the currently selected item. hope this helps!! regards ~Hari~

              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