MFC list view control question....
-
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!
-
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!
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
-
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!
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
-
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
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!!
-
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
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
-
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
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'sTable
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 -
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'sTable
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.comso 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! :)
-
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! :)
You can associate application specific data with items in a list control by calling
CListCtrl::SetItemData()
. Typically, the item data (aDWORD
) 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 -
You can associate application specific data with items in a list control by calling
CListCtrl::SetItemData()
. Typically, the item data (aDWORD
) 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 -
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'sTable
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.comThanks for the info, Ravi. Nish :) My most recent CP article :- A newbie's elementary guide to spawning processes www.busterboy.org