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. MFC list view control question....

MFC list view control question....

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
10 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.
  • D Offline
    D Offline
    David Z
    wrote on last edited by
    #1

    This is probably going to make some of you laugh but here goes :) I have a dialog base MFC app with a list control in report view. How can i copy the data in the list view class to another list view class in a child window? I have the child window pop up mapped to a button event. Would i have to create a loop to copy the data? or is there a faster way. Please help, Thanks!

    N R 2 Replies Last reply
    0
    • D David Z

      This is probably going to make some of you laugh but here goes :) I have a dialog base MFC app with a list control in report view. How can i copy the data in the list view class to another list view class in a child window? I have the child window pop up mapped to a button event. Would i have to create a loop to copy the data? or is there a faster way. Please help, Thanks!

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      David Z wrote: Would i have to create a loop to copy the data? or is there a faster way. I reckon you'd have to loop through the data. I dont think there is a faster way. I might be wrong though. Nish My most recent CP article :- A newbie's elementary guide to spawning processes www.busterboy.org

      1 Reply Last reply
      0
      • D David Z

        This is probably going to make some of you laugh but here goes :) I have a dialog base MFC app with a list control in report view. How can i copy the data in the list view class to another list view class in a child window? I have the child window pop up mapped to a button event. Would i have to create a loop to copy the data? or is there a faster way. Please help, Thanks!

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        If you use the item data field of each list control entry, you could quickly copy just the item data instead of all the column text. In general, this is a better design pattern (Model-View) than stuffing text in a list control. In other words, a list control should know how to render itself based on the data model. /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

        D N 2 Replies Last reply
        0
        • R Ravi Bhavnani

          If you use the item data field of each list control entry, you could quickly copy just the item data instead of all the column text. In general, this is a better design pattern (Model-View) than stuffing text in a list control. In other words, a list control should know how to render itself based on the data model. /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

          D Offline
          D Offline
          David Z
          wrote on last edited by
          #4

          Well, I am using the LV_ITEM datatype for the list. So I guess I should make it into a member variable and access it through scoping?? But wouldn't I still have to get the number of items and loop through inserting each one? I'm not quite understanding your suggestion ravi :) Can you please be a little more specific, like including a declaration example and how I should initialize my child diag class and/or duplicate list view class. Thanks for the replies!!

          1 Reply Last reply
          0
          • R Ravi Bhavnani

            If you use the item data field of each list control entry, you could quickly copy just the item data instead of all the column text. In general, this is a better design pattern (Model-View) than stuffing text in a list control. In other words, a list control should know how to render itself based on the data model. /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

            N Offline
            N Offline
            Nish Nishant
            wrote on last edited by
            #5

            Ravi Bhavnani wrote: If you use the item data field of each list control entry, you could quickly copy just the item data instead of all the column text But this is assuming that he has only one column of data. What if he has 2 or more cols? Nish My most recent CP article :- A newbie's elementary guide to spawning processes www.busterboy.org

            R 1 Reply Last reply
            0
            • N Nish Nishant

              Ravi Bhavnani wrote: If you use the item data field of each list control entry, you could quickly copy just the item data instead of all the column text But this is assuming that he has only one column of data. What if he has 2 or more cols? Nish My most recent CP article :- A newbie's elementary guide to spawning processes www.busterboy.org

              R Offline
              R Offline
              Ravi Bhavnani
              wrote on last edited by
              #6

              Nish [BusterBoy] wrote: But this is assuming that he has only one column of data. Actually, no. The item data is just a pointer to a blob of data that can be rendered in any manner in the list control. For example, the item data could point to a CMumble object that has multiple members, each rendered in a column. This is how Java's Table UI widget works. It's nice and clean because it separates the data model from the rendering. /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

              D N 2 Replies Last reply
              0
              • R Ravi Bhavnani

                Nish [BusterBoy] wrote: But this is assuming that he has only one column of data. Actually, no. The item data is just a pointer to a blob of data that can be rendered in any manner in the list control. For example, the item data could point to a CMumble object that has multiple members, each rendered in a column. This is how Java's Table UI widget works. It's nice and clean because it separates the data model from the rendering. /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

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

                so how exactly should I declare this item data type?? I looked around MSDN and it seems like my LV_ITEM datatype is not quite the same as what you are talking about ravi. How should I declare that kind of datatype and some example of how to use it would be awesome! Thanks for all the comments! :)

                R 1 Reply Last reply
                0
                • D David Z

                  so how exactly should I declare this item data type?? I looked around MSDN and it seems like my LV_ITEM datatype is not quite the same as what you are talking about ravi. How should I declare that kind of datatype and some example of how to use it would be awesome! Thanks for all the comments! :)

                  R Offline
                  R Offline
                  Ravi Bhavnani
                  wrote on last edited by
                  #8

                  You can associate application specific data with items in a list control by calling CListCtrl::SetItemData(). Typically, the item data (a DWORD) is a pointer to an object whose information will be rendered by the list control for that row. Aside: The object represents the "model" and the list control (whose only job is to render items and be responsive to mouse and keyclicks) represents the "view" and "controller" in the MVC (model-view-controller) design pattern. Your (owner drawn) list control will display the appropriate information in each column based on the item's data. When you want to copy chunks of one list control to another (or even within the same list control), all you need to do is to update the target list control's item data for the appropriate rows and invalidate the list control (to force a redraw). You don't need to copy the actual column data of the rows being copied. /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

                  D 1 Reply Last reply
                  0
                  • R Ravi Bhavnani

                    You can associate application specific data with items in a list control by calling CListCtrl::SetItemData(). Typically, the item data (a DWORD) is a pointer to an object whose information will be rendered by the list control for that row. Aside: The object represents the "model" and the list control (whose only job is to render items and be responsive to mouse and keyclicks) represents the "view" and "controller" in the MVC (model-view-controller) design pattern. Your (owner drawn) list control will display the appropriate information in each column based on the item's data. When you want to copy chunks of one list control to another (or even within the same list control), all you need to do is to update the target list control's item data for the appropriate rows and invalidate the list control (to force a redraw). You don't need to copy the actual column data of the rows being copied. /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

                    D Offline
                    D Offline
                    David Z
                    wrote on last edited by
                    #9

                    That's a really cool solution! I seemed to have missed that member function looking through MSDN :). That should solve my problem, thanks for everyone's help!

                    1 Reply Last reply
                    0
                    • R Ravi Bhavnani

                      Nish [BusterBoy] wrote: But this is assuming that he has only one column of data. Actually, no. The item data is just a pointer to a blob of data that can be rendered in any manner in the list control. For example, the item data could point to a CMumble object that has multiple members, each rendered in a column. This is how Java's Table UI widget works. It's nice and clean because it separates the data model from the rendering. /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

                      N Offline
                      N Offline
                      Nish Nishant
                      wrote on last edited by
                      #10

                      Thanks for the info, Ravi. Nish :) My most recent CP article :- A newbie's elementary guide to spawning processes www.busterboy.org

                      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