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. adding items to list box

adding items to list box

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorialquestionlearning
18 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.
  • T toxcct

    m_List seems to be a CString object, not a list !!! how do you declare it ??

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

    i just created member variable for IDC_LIST (list box) using MFC class wizard. there i declared m_LIST of type CString. i have just started with vc+ i have no idea how these things works. can u plz help me in adding items to list box and deleting item from list box.

    T S D 3 Replies Last reply
    0
    • P parichaybp

      i just created member variable for IDC_LIST (list box) using MFC class wizard. there i declared m_LIST of type CString. i have just started with vc+ i have no idea how these things works. can u plz help me in adding items to list box and deleting item from list box.

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #7

      AddString() is not a member of the CString[^] class. what did you want to do with this ? if IDC_LIST is a CListBox, it doesn't have any sense to associate it to a CString variable !!! explain you wished algorithm for that OnAdd() method please...

      P 1 Reply Last reply
      0
      • T toxcct

        AddString() is not a member of the CString[^] class. what did you want to do with this ? if IDC_LIST is a CListBox, it doesn't have any sense to associate it to a CString variable !!! explain you wished algorithm for that OnAdd() method please...

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

        The problem is i have created a list box with add , remove button & edit box. during the execution of the program i want the contents of the edit box to be added to list box when i click on add button. so tell me hw to start working with list box and declaring member variables for list box.. where and which function in my program i have use.

        T 1 Reply Last reply
        0
        • P parichaybp

          i just created member variable for IDC_LIST (list box) using MFC class wizard. there i declared m_LIST of type CString. i have just started with vc+ i have no idea how these things works. can u plz help me in adding items to list box and deleting item from list box.

          S Offline
          S Offline
          scoroop
          wrote on last edited by
          #9

          read this carefully http://codeproject.com/combobox/listbox\_tut.asp

          1 Reply Last reply
          0
          • P parichaybp

            The problem is i have created a list box with add , remove button & edit box. during the execution of the program i want the contents of the edit box to be added to list box when i click on add button. so tell me hw to start working with list box and declaring member variables for list box.. where and which function in my program i have use.

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #10

            the list is a list (CListCtrl), and the edit stays an edit (CEdit). what you have to do is : 1. read the edit 2. add to the list

            CString strCaption;
            m_Edit.GetWindowText(strCaption);
            m_List.AddString(strCaption);

            do you understand it better now ?

            P 1 Reply Last reply
            0
            • P parichaybp

              Hi, i just added addstring code to project for add button but i am getting the below error. ////code///// void CUpdateDlg::OnAdd() { m_LIST.AddString("Welcome"); } ///////////// Error:- Compiling... UpdateDlg.cpp D:\Parichay\DesktopSearch\UpdateDlg.cpp(63) : error C2039: 'AddString' : is not a member of 'CString' c:\program files\microsoft visual studio\vc98\mfc\include\afx.h(368) : see declaration of 'CString' Error executing cl.exe. DesktopSearch.exe - 1 error(s), 0 warning(s) Regards, Parichay B.P

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

              parichaybp, AddString is function in CListBox not CString you should declare a variable ListBox: you eneter ListBox Control in your form and then right click in control(ListBox) and declare a variable for this control Now you can use this this function or functions You can use this code CString Str; Str="This is test"; m_List.AddString(Str); or other functions

              T P 3 Replies Last reply
              0
              • H Hamid Taebi

                parichaybp, AddString is function in CListBox not CString you should declare a variable ListBox: you eneter ListBox Control in your form and then right click in control(ListBox) and declare a variable for this control Now you can use this this function or functions You can use this code CString Str; Str="This is test"; m_List.AddString(Str); or other functions

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #12

                WhiteSky, i have one question for you : 1. do you read the other answers when replying to a post ? 2. (implisit one) Why do you repeat my answers ? X| :suss:

                H 1 Reply Last reply
                0
                • H Hamid Taebi

                  parichaybp, AddString is function in CListBox not CString you should declare a variable ListBox: you eneter ListBox Control in your form and then right click in control(ListBox) and declare a variable for this control Now you can use this this function or functions You can use this code CString Str; Str="This is test"; m_List.AddString(Str); or other functions

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

                  Thanks its working. items are getting added.

                  1 Reply Last reply
                  0
                  • H Hamid Taebi

                    parichaybp, AddString is function in CListBox not CString you should declare a variable ListBox: you eneter ListBox Control in your form and then right click in control(ListBox) and declare a variable for this control Now you can use this this function or functions You can use this code CString Str; Str="This is test"; m_List.AddString(Str); or other functions

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

                    one more thing how to remove the selected the item from list box using the remove button.

                    1 Reply Last reply
                    0
                    • T toxcct

                      WhiteSky, i have one question for you : 1. do you read the other answers when replying to a post ? 2. (implisit one) Why do you repeat my answers ? X| :suss:

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

                      whats happen? 1-yes i see all answers, but sender reply to my answer well I should reply to question(parichaybp ) 2-you're good programer,and if my answer and your answer is equal because question is same (:rose: is good ) And have a nice day

                      1 Reply Last reply
                      0
                      • T toxcct

                        the list is a list (CListCtrl), and the edit stays an edit (CEdit). what you have to do is : 1. read the edit 2. add to the list

                        CString strCaption;
                        m_Edit.GetWindowText(strCaption);
                        m_List.AddString(strCaption);

                        do you understand it better now ?

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

                        can u plz tell how to remove the item using the remove button and reset the list

                        T 1 Reply Last reply
                        0
                        • P parichaybp

                          can u plz tell how to remove the item using the remove button and reset the list

                          T Offline
                          T Offline
                          toxcct
                          wrote on last edited by
                          #17

                          CListCtrl::DeleteItem()[^] should do...

                          1 Reply Last reply
                          0
                          • P parichaybp

                            i just created member variable for IDC_LIST (list box) using MFC class wizard. there i declared m_LIST of type CString. i have just started with vc+ i have no idea how these things works. can u plz help me in adding items to list box and deleting item from list box.

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

                            parichaybp wrote:

                            there i declared m_LIST of type CString.

                            Delete the variable and recreate it as a CListBox instead.


                            "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                            "There is no death, only a change of worlds." - Native American Proverb

                            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