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. List box control

List box control

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
15 Posts 4 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 Pazzuzu

    Okay Thanks, Could u please tell me how to achieve the above said things using the CListView control. By [2],I mean to make the listview control to the size of the dialog,while displaying & not to the size of the view. By ListView control,did u mean list control co's,while in the control tool box,I see only list contol & listbox control

    D Offline
    D Offline
    Dreamz
    wrote on last edited by
    #5

    It is CListCtrl. You can use these functions of the class eg: To add columns m_ListCtrl.InsertColumn(1,"1st Column"); To add data to the control m_ListCtrl.InsertItem(0,"Data"); m_ListCtrl.SetItemText(0,1,"Value");

    P 1 Reply Last reply
    0
    • D Dreamz

      It is CListCtrl. You can use these functions of the class eg: To add columns m_ListCtrl.InsertColumn(1,"1st Column"); To add data to the control m_ListCtrl.InsertItem(0,"Data"); m_ListCtrl.SetItemText(0,1,"Value");

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

      How will I connect my view class which is derived from Cview to the control object,Co's I want to test the list control Did as follows: On the,"OnCreate" function of my view class,I did as follows m_lstctrl.Create(WS_CHILD|WS_VISIBLE|LBS_STANDARD|WS_HSCROLL, CRect(10,10,200,200),this, IDC_TEST); m_lstctrl.InsertColumn(1,"1st Column"); But I dont see any columns ,apart from the listctrl box boundary...

      D 1 Reply Last reply
      0
      • P Pazzuzu

        Hi Guys, Iam writing an MFC application with a dialog having a listbox control. In the view header class,have the ListBox object as a member variable. CListBox m_ListBox; The questions I have are: [1]How will I create a Listbox control used the "m_ListBox.Create"- How will I pass the cDialog class as I have to pass a "pParentWnd parameter" which expects a CWindow object [2]How to make the listbox control,Dialog & view class of the same size. [3] Want to add 2 columns in the list box,a header row, with constant values. 1st column 2nd column ************* *********** FixedLineNumber; 5 StartLineNumber; 10 NumberOfLines; 4 FixedLength; 15 CharacterLength; 10 CharacterOffset; 5 and fill the 2 columns with values as above. the first column contain constant texts & the second coumn,I want to fill with values... Any help is appreciated....

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

        Pazzuzu wrote: [1]How will I create a Listbox control used the "m_ListBox.Create"- How will I pass the cDialog class as I have to pass a "pParentWnd parameter" which expects a CWindow object Unless you absolutely have to, it's easier to create the control at design-time rather than at run-time. As to your question about the Create() method, the third parameter would be the this pointer. For example:

        BOOL CMyDialog::OnInitDialog()
        {
        m_listbox.Create(..., this, IDC_LISTBOX1);
        return TRUE;
        }

        Pazzuzu wrote: [3] Want to add 2 columns in the list box,a header row, with constant values. You can do this with a listbox (by using tab stops), but as already mentioned, it's much easier with a list control.


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        1 Reply Last reply
        0
        • P Pazzuzu

          How will I connect my view class which is derived from Cview to the control object,Co's I want to test the list control Did as follows: On the,"OnCreate" function of my view class,I did as follows m_lstctrl.Create(WS_CHILD|WS_VISIBLE|LBS_STANDARD|WS_HSCROLL, CRect(10,10,200,200),this, IDC_TEST); m_lstctrl.InsertColumn(1,"1st Column"); But I dont see any columns ,apart from the listctrl box boundary...

          D Offline
          D Offline
          Dreamz
          wrote on last edited by
          #8

          Replace LBS_STANDARD by LVS_REPORT.

          P 1 Reply Last reply
          0
          • D Dreamz

            Replace LBS_STANDARD by LVS_REPORT.

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

            Thanks Dreamz.Now I see the control on screen. But the size is small. How can I set the size of the ctrl in code.. Thanks all......

            D D 2 Replies Last reply
            0
            • P Pazzuzu

              Thanks Dreamz.Now I see the control on screen. But the size is small. How can I set the size of the ctrl in code.. Thanks all......

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

              Pazzuzu wrote: How can I set the size of the ctrl in code.. Check out the second parameter to Create().


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              P 1 Reply Last reply
              0
              • D David Crow

                Pazzuzu wrote: How can I set the size of the ctrl in code.. Check out the second parameter to Create().


                "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

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

                Thanks then.....

                1 Reply Last reply
                0
                • P Pazzuzu

                  Thanks Dreamz.Now I see the control on screen. But the size is small. How can I set the size of the ctrl in code.. Thanks all......

                  D Offline
                  D Offline
                  Dreamz
                  wrote on last edited by
                  #12

                  You can adjust the CRect(..) in the Create function. Or add WS_SIZEBOX style,then you can resize the control at runtime.

                  1 Reply Last reply
                  0
                  • P Pazzuzu

                    Okay Thanks, Could u please tell me how to achieve the above said things using the CListView control. By [2],I mean to make the listview control to the size of the dialog,while displaying & not to the size of the view. By ListView control,did u mean list control co's,while in the control tool box,I see only list contol & listbox control

                    P Offline
                    P Offline
                    Peter Mares
                    wrote on last edited by
                    #13

                    ok, to add columns to the list control, make sure that you create the control with the LVS_REPORT style. then call CListCtrl::InsertColumn() to add a column and then CListCtrl::InsertItem() to add items. I saw a post that already indicated this. Now to the problem of sizing the control to the size of your dialog: In the dialog class, handle the WM_SIZE message, call GetClientRect() to get the current client rectangle of the dialog and then just call CListCtrl::MoveWindow() to size the list control to the size of the dialog. HOpefully that explains it. Ciao


                    controlSHIFT [Glossary Manager] [AfterThought Backup Lite] All good things were meant to be improved

                    P 2 Replies Last reply
                    0
                    • P Peter Mares

                      ok, to add columns to the list control, make sure that you create the control with the LVS_REPORT style. then call CListCtrl::InsertColumn() to add a column and then CListCtrl::InsertItem() to add items. I saw a post that already indicated this. Now to the problem of sizing the control to the size of your dialog: In the dialog class, handle the WM_SIZE message, call GetClientRect() to get the current client rectangle of the dialog and then just call CListCtrl::MoveWindow() to size the list control to the size of the dialog. HOpefully that explains it. Ciao


                      controlSHIFT [Glossary Manager] [AfterThought Backup Lite] All good things were meant to be improved

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

                      Thanks guys...

                      1 Reply Last reply
                      0
                      • P Peter Mares

                        ok, to add columns to the list control, make sure that you create the control with the LVS_REPORT style. then call CListCtrl::InsertColumn() to add a column and then CListCtrl::InsertItem() to add items. I saw a post that already indicated this. Now to the problem of sizing the control to the size of your dialog: In the dialog class, handle the WM_SIZE message, call GetClientRect() to get the current client rectangle of the dialog and then just call CListCtrl::MoveWindow() to size the list control to the size of the dialog. HOpefully that explains it. Ciao


                        controlSHIFT [Glossary Manager] [AfterThought Backup Lite] All good things were meant to be improved

                        P Offline
                        P Offline
                        Pazzuzu
                        wrote on last edited by
                        #15

                        Thank You Guys....

                        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