How do I copy the contents of a CListCtrl object ?
-
I have a CListCtrl member in my dialog. During runtime, I fill the control's columns and rows with data using 'InsertColumn' and 'SetItemText' functions. Note : This List Control contains 5 rows and 3 columns full of data. Now, I want a copy of the data of the whole list control in another ClistCtrl object which I create during runtime using CListCtrl's Create function. How can I do this since I don't have a 'Copy' function as for data structures like CStringArray.
-
I have a CListCtrl member in my dialog. During runtime, I fill the control's columns and rows with data using 'InsertColumn' and 'SetItemText' functions. Note : This List Control contains 5 rows and 3 columns full of data. Now, I want a copy of the data of the whole list control in another ClistCtrl object which I create during runtime using CListCtrl's Create function. How can I do this since I don't have a 'Copy' function as for data structures like CStringArray.
There is no LB_CLONE_FROM_OTHER list control message, so you're going to have to roll your sleeves up and do it yourself. If you already have code to fill up the first control, can you move that into a function, and call it with either
CListCtrl *
or a dlg ID? Or if this will change over time, write a cloning function? Get the number of columns / rows of the first control, set the second one to the same. Call GetItem a lot on the first control, and SetItem a lot on the second? You'll have to be careful. One thing I can think of is an items lParam - if it is a casted pointer, can you use the same pointer? Or make a new object to point to? Etc. That sort of thing is application specific though. Iain.