How can I convert an object to ArrayList
-
I want to convert object to Array List but stuck how to do. Actually I am doing this because I am passing argument of an array this array is contains some panels. When I pass these panels to another form it copy the references of panels. Any thing changes in child form(in panels ) affect the father form panels. Here is the code.
object obj = array.Clone();
Now the object become object array but there is no technique to convert this obj to object[]. If you have any suggestion to overcome my problem to not copy the references of the array(panels) . You are most welcome if you give any suggestion.
-
I want to convert object to Array List but stuck how to do. Actually I am doing this because I am passing argument of an array this array is contains some panels. When I pass these panels to another form it copy the references of panels. Any thing changes in child form(in panels ) affect the father form panels. Here is the code.
object obj = array.Clone();
Now the object become object array but there is no technique to convert this obj to object[]. If you have any suggestion to overcome my problem to not copy the references of the array(panels) . You are most welcome if you give any suggestion.
Naveed khan nido wrote:
but there is no technique to convert this obj to object[].
object[] obj = (object[])obj
Navaneeth How to use google | Ask smart questions
-
I want to convert object to Array List but stuck how to do. Actually I am doing this because I am passing argument of an array this array is contains some panels. When I pass these panels to another form it copy the references of panels. Any thing changes in child form(in panels ) affect the father form panels. Here is the code.
object obj = array.Clone();
Now the object become object array but there is no technique to convert this obj to object[]. If you have any suggestion to overcome my problem to not copy the references of the array(panels) . You are most welcome if you give any suggestion.
Cloning the array won't help solve your problem - the array will get cloned, not the elements in the array. The panel objects will still be shared. You can deep clone i.e. clone the panels themselves. What are you trying to do though?
Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
-
Cloning the array won't help solve your problem - the array will get cloned, not the elements in the array. The panel objects will still be shared. You can deep clone i.e. clone the panels themselves. What are you trying to do though?
Regards Senthil [MVP - Visual C#] _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro
yes you are right. It is still coping the references. The thing I am doing is that I have an array of panels and these panels have some Labels and Picture Boxes. Now I am going to create an another form and need a copy of these panels and the objects that panels contains. In another form it will further changes(i,e Labels or Pic Boxes) that changes should not made to Parent Form. So what should I do. Can you give me an example of deep clone. How should solve my problem. thanks for reply.
-
Naveed khan nido wrote:
but there is no technique to convert this obj to object[].
object[] obj = (object[])obj
Navaneeth How to use google | Ask smart questions
-
yes you are right. It is still coping the references. The thing I am doing is that I have an array of panels and these panels have some Labels and Picture Boxes. Now I am going to create an another form and need a copy of these panels and the objects that panels contains. In another form it will further changes(i,e Labels or Pic Boxes) that changes should not made to Parent Form. So what should I do. Can you give me an example of deep clone. How should solve my problem. thanks for reply.
You could write a function that will do the deep clone for you...
It's not a bug, it's a feature! Me in Softwareland.
-
yes you are right. It is still coping the references. The thing I am doing is that I have an array of panels and these panels have some Labels and Picture Boxes. Now I am going to create an another form and need a copy of these panels and the objects that panels contains. In another form it will further changes(i,e Labels or Pic Boxes) that changes should not made to Parent Form. So what should I do. Can you give me an example of deep clone. How should solve my problem. thanks for reply.
Just a thought. You might be better off converting these panels into custom controls. That way you can create the second form by just dropping the custom control in. Then create a class or struct with fields for the information from form 1, instantiate the class/struct with the data from form 1 and pass it to second form whre data gets inserted into custom control.
Henry Minute If you open a can of worms, any viable solution *MUST* involve a larger can.