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. Adding Items ti List control

Adding Items ti List control

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
19 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.
  • V voorugonda prashanth

    hi parichaya, u want to add to ListBox or ListControl? r u from AP?

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

    Hi, its List Control. I am from Bangalore.

    V 1 Reply Last reply
    0
    • N Nibu babu thomas

      Use InsertItem of CListCtrl. There is an example in MSDN related to this. Please look up InsertItem. I guess here you will have to use the report style(LVS_REPORT).


      Nibu thomas Software Developer Faqs by Michael dunn

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

      Hi, Thanks for the reply..I just checked the MSDN Ex.. --------------------- Example MSDN // The pointer to my list view control. extern CListCtrl* pmyListCtrl; CString strText; int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount(); // Insert 10 items in the list view control. for (int i=0;i < 10;i++) { strText.Format(TEXT("item %d"), i); // Insert the item, select every other item. pmyListCtrl->InsertItem( LVIF_TEXT|LVIF_STATE, i, strText, (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED, 0, 0); // Initialize the text of the subitems. for (int j=1;j < nColumnCount;j++) { strText.Format(TEXT("sub-item %d %d"), i, j); pmyListCtrl->SetItemText(i, j, strText); } } ---------------------------------------- extern CListCtrl* pmyListCtrl; can u tell me what the use of the above statment ??

      N M 3 Replies Last reply
      0
      • P parichaybp

        Hi, Thanks for the reply..I just checked the MSDN Ex.. --------------------- Example MSDN // The pointer to my list view control. extern CListCtrl* pmyListCtrl; CString strText; int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount(); // Insert 10 items in the list view control. for (int i=0;i < 10;i++) { strText.Format(TEXT("item %d"), i); // Insert the item, select every other item. pmyListCtrl->InsertItem( LVIF_TEXT|LVIF_STATE, i, strText, (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED, 0, 0); // Initialize the text of the subitems. for (int j=1;j < nColumnCount;j++) { strText.Format(TEXT("sub-item %d %d"), i, j); pmyListCtrl->SetItemText(i, j, strText); } } ---------------------------------------- extern CListCtrl* pmyListCtrl; can u tell me what the use of the above statment ??

        N Offline
        N Offline
        Nibu babu thomas
        wrote on last edited by
        #8

        parichaybp wrote:

        extern CListCtrl* pmyListCtrl; can u tell me what the use of the above statment ??

        This is just an indication that pmyListCtrl is declared elsewhere. Most of the samples have this kind of declaration. You can ignore this and concentrate on the essentials.


        Nibu thomas Software Developer Faqs by Michael dunn

        1 Reply Last reply
        0
        • P parichaybp

          Hi, Thanks for the reply..I just checked the MSDN Ex.. --------------------- Example MSDN // The pointer to my list view control. extern CListCtrl* pmyListCtrl; CString strText; int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount(); // Insert 10 items in the list view control. for (int i=0;i < 10;i++) { strText.Format(TEXT("item %d"), i); // Insert the item, select every other item. pmyListCtrl->InsertItem( LVIF_TEXT|LVIF_STATE, i, strText, (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED, 0, 0); // Initialize the text of the subitems. for (int j=1;j < nColumnCount;j++) { strText.Format(TEXT("sub-item %d %d"), i, j); pmyListCtrl->SetItemText(i, j, strText); } } ---------------------------------------- extern CListCtrl* pmyListCtrl; can u tell me what the use of the above statment ??

          M Offline
          M Offline
          Maxwell Chen
          wrote on last edited by
          #9

          parichaybp wrote:

          extern CListCtrl* pmyListCtrl;

          Meaning the variable CListCtrl* pmyListCtrl is declared somewhere else (another .cpp file) outside this cpp file.


          Maxwell Chen

          P 1 Reply Last reply
          0
          • P parichaybp

            Hi , From the below code it displays the file name on the output screen,can anyone please tell how to add them to List box ?? I have list box IDC_OUTPUT CListCtrl m_output. ----------------------------------- if (e != NULL) { readFiles (e->left); fp = fopen (e->filename, "r"); fnum++; if ((s = (char*)strrchr(e->filename, '/')) == NULL) cout << e->filename; //Prints file name else cout << e->filename; //Prints File name insert (fnum, e->filename); if (fp) { wds = getWord (fp,fnum); } cout << " (" << wds << " words)" << endl; //Prints number of words fclose (fp); ------------------------------------ Regards, Parichay.

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

            void CAnswerView::FillList(CListCtrl *m_ListCtrl,CListBox *m_ListBox,CString str) { if(m_ListCtrl) { LV_ITEM Item2={0}; Item2 .mask = LVIF_TEXT| LVIF_STATE|LVIF_PARAM; Item2 .iItem =m_ListCtrl->GetItemCount(); Item2 .pszText = CA2T(str); Item2 .stateMask = LVIS_STATEIMAGEMASK; Item2 .state = INDEXTOSTATEIMAGEMASK(1); m_ListCtrl->InsertItem( &Item2); } if(m_ListBox) { m_ListBox->AddString(str); m_ListBox->InsertString(0,str); } }

            P 1 Reply Last reply
            0
            • M Maxwell Chen

              parichaybp wrote:

              extern CListCtrl* pmyListCtrl;

              Meaning the variable CListCtrl* pmyListCtrl is declared somewhere else (another .cpp file) outside this cpp file.


              Maxwell Chen

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

              Hi Maxwell Chen, Hope U still Remember me..:) i just tried with this statment CString strText = "hello"; m_OUTPUT->SetItemText(1, 1, strText); is this correct ???

              M 1 Reply Last reply
              0
              • P parichaybp

                Hi Maxwell Chen, Hope U still Remember me..:) i just tried with this statment CString strText = "hello"; m_OUTPUT->SetItemText(1, 1, strText); is this correct ???

                M Offline
                M Offline
                Maxwell Chen
                wrote on last edited by
                #12

                Yes I remember you. Regarding to a CListCtrl, you had better use the structured data to feed it. As what WhiteSky has provided (THE REPLY[^]) 3 min earlier. [Edit] A second method is to use CListCtrl::InsertItem(nIndex, sStr), if it contains only one column. [/Edit]


                Maxwell Chen

                1 Reply Last reply
                0
                • H Hamid Taebi

                  void CAnswerView::FillList(CListCtrl *m_ListCtrl,CListBox *m_ListBox,CString str) { if(m_ListCtrl) { LV_ITEM Item2={0}; Item2 .mask = LVIF_TEXT| LVIF_STATE|LVIF_PARAM; Item2 .iItem =m_ListCtrl->GetItemCount(); Item2 .pszText = CA2T(str); Item2 .stateMask = LVIS_STATEIMAGEMASK; Item2 .state = INDEXTOSTATEIMAGEMASK(1); m_ListCtrl->InsertItem( &Item2); } if(m_ListBox) { m_ListBox->AddString(str); m_ListBox->InsertString(0,str); } }

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

                  Hi WhiteSky, CListCtrl *m_OUTPUT; CString strText = "hello"; m_OUTPUT->SetItemText(1, 1, strText); is the above statment correct ?? i tryed but its not giveing any output.

                  M H 2 Replies Last reply
                  0
                  • P parichaybp

                    Hi WhiteSky, CListCtrl *m_OUTPUT; CString strText = "hello"; m_OUTPUT->SetItemText(1, 1, strText); is the above statment correct ?? i tryed but its not giveing any output.

                    M Offline
                    M Offline
                    Maxwell Chen
                    wrote on last edited by
                    #14

                    CListCtrl::SetItemText is to alter the text of an existing entry in that CListCtrl. If there has not any entry in that control, what you are using is invalid. Thus we have suggested you to use CListCtrl::InsertItem.


                    Maxwell Chen

                    1 Reply Last reply
                    0
                    • P parichaybp

                      Hi WhiteSky, CListCtrl *m_OUTPUT; CString strText = "hello"; m_OUTPUT->SetItemText(1, 1, strText); is the above statment correct ?? i tryed but its not giveing any output.

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

                      I suggest that you read Msdn also example from ClistCtrl

                      1 Reply Last reply
                      0
                      • P parichaybp

                        Hi, Thanks for the reply..I just checked the MSDN Ex.. --------------------- Example MSDN // The pointer to my list view control. extern CListCtrl* pmyListCtrl; CString strText; int nColumnCount = pmyListCtrl->GetHeaderCtrl()->GetItemCount(); // Insert 10 items in the list view control. for (int i=0;i < 10;i++) { strText.Format(TEXT("item %d"), i); // Insert the item, select every other item. pmyListCtrl->InsertItem( LVIF_TEXT|LVIF_STATE, i, strText, (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED, 0, 0); // Initialize the text of the subitems. for (int j=1;j < nColumnCount;j++) { strText.Format(TEXT("sub-item %d %d"), i, j); pmyListCtrl->SetItemText(i, j, strText); } } ---------------------------------------- extern CListCtrl* pmyListCtrl; can u tell me what the use of the above statment ??

                        M Offline
                        M Offline
                        Maxwell Chen
                        wrote on last edited by
                        #16

                        parichaybp wrote:

                        extern CListCtrl* pmyListCtrl; can u tell me what the use of the above statment ??

                        And that's why I have suggested you to read a book about the syntax of C++ Language.


                        Maxwell Chen

                        1 Reply Last reply
                        0
                        • P parichaybp

                          Hi, its List Control. I am from Bangalore.

                          V Offline
                          V Offline
                          voorugonda prashanth
                          wrote on last edited by
                          #17

                          hii, where r u working in b'lore?

                          P 1 Reply Last reply
                          0
                          • V voorugonda prashanth

                            hii, where r u working in b'lore?

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

                            Hey i am nt working,i am doing my MCA project work.

                            V 1 Reply Last reply
                            0
                            • P parichaybp

                              Hey i am nt working,i am doing my MCA project work.

                              V Offline
                              V Offline
                              voorugonda prashanth
                              wrote on last edited by
                              #19

                              good. may i know on which project u r doing? ur name?

                              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