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. access and deleting of ListBox items

access and deleting of ListBox items

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

    Hi, I have created IDC_LIST (list box) of type ClistBox and Member m_list. For Add items I am using m_list.AddString(szDir); & for reset the list I am using m_list.ResetContent(); both this are working fine. Can anyone tell me how to delete a item from list ? if I have 5 items in my list box if I have selected 4th item in the list box after pressing delete button I want that 4 item to be removed from list how to do that ?? And also I want to access all items of the list box in other functions. Regards, Parichay B.P

    H N 3 Replies Last reply
    0
    • P parichaybp

      Hi, I have created IDC_LIST (list box) of type ClistBox and Member m_list. For Add items I am using m_list.AddString(szDir); & for reset the list I am using m_list.ResetContent(); both this are working fine. Can anyone tell me how to delete a item from list ? if I have 5 items in my list box if I have selected 4th item in the list box after pressing delete button I want that 4 item to be removed from list how to do that ?? And also I want to access all items of the list box in other functions. Regards, Parichay B.P

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      Hi parichaybp , for delete from ListBox use DeleteString

      P 1 Reply Last reply
      0
      • P parichaybp

        Hi, I have created IDC_LIST (list box) of type ClistBox and Member m_list. For Add items I am using m_list.AddString(szDir); & for reset the list I am using m_list.ResetContent(); both this are working fine. Can anyone tell me how to delete a item from list ? if I have 5 items in my list box if I have selected 4th item in the list box after pressing delete button I want that 4 item to be removed from list how to do that ?? And also I want to access all items of the list box in other functions. Regards, Parichay B.P

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

        use DeleteString() if u want to delete an item from the list. To get the index of currently seleted item use GetCurSel()... m_list.DeleteString( m_list.GetCurSel() ); if u want to get all the items in the list ..... int nCount = m_list.GetCount(); for(int nIdx = 0;nIdx< nCount;nIdx++) { CString csText; m_list.GetText( nIdx, csText ); // u will get the text in csText } nave

        P 1 Reply Last reply
        0
        • H Hamid Taebi

          Hi parichaybp , for delete from ListBox use DeleteString

          P Offline
          P Offline
          parichaybp
          wrote on last edited by
          #4

          m_list.DeleteString(); its working but i want to know how to remove the selected item?? what parameter have to passed ??? how to access the selected item and remove it?? and plz also tell how to access all the list items???

          1 Reply Last reply
          0
          • N Naveen

            use DeleteString() if u want to delete an item from the list. To get the index of currently seleted item use GetCurSel()... m_list.DeleteString( m_list.GetCurSel() ); if u want to get all the items in the list ..... int nCount = m_list.GetCount(); for(int nIdx = 0;nIdx< nCount;nIdx++) { CString csText; m_list.GetText( nIdx, csText ); // u will get the text in csText } nave

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

            Thanks both are working.

            1 Reply Last reply
            0
            • P parichaybp

              Hi, I have created IDC_LIST (list box) of type ClistBox and Member m_list. For Add items I am using m_list.AddString(szDir); & for reset the list I am using m_list.ResetContent(); both this are working fine. Can anyone tell me how to delete a item from list ? if I have 5 items in my list box if I have selected 4th item in the list box after pressing delete button I want that 4 item to be removed from list how to do that ?? And also I want to access all items of the list box in other functions. Regards, Parichay B.P

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              ///////This example for Delete/Insert / read and count And Create //But you dont need to create list becuase you have control in your form CListBox m_List2; m_List2.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,100,100),this,1); m_List2.AddString("1"); m_List2.AddString("2"); m_List2.AddString("3"); m_List2.AddString("4"); //For Delete from ListBox m_List2.DeleteString(0);//Delete 1//m_List2.GetCurSel() //////For GetItems CString Str,temp,Str2,Str3; CStringArray m_String; for(int i = 0;i< m_List2.GetCount();i++) { m_List2.GetText( i, temp); Str.Insert(0,"\\"+temp);//insert in location 0 Str3.Insert(Str3.GetLength(),"\\"+temp);//insert in location end Str2=Str2+"\\"+temp;//insert 1\2\3 m_String.Add(temp);//insert to array }

              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