Hi ManasMSDN,
Did you mean the properties' value of the car are lost when you close the collection editor at design time? If so, I am not suffering this problem by copying and pasting your code directly.
To keep the value persist, I think you are doing right. Apply theDesignerSerializationVisibility attribute to the Car property and pass theDesignerSerializationVisibility.Content as the value of the parameter.
Take a look at the following code. When we set value for the car instance in the PropertyGrid at design time. The designer will serialize the coe in the initializeComponent method. As we can see the values we are setting are persisted in this case.
| // |
| //xyz1 |
| // |
| car1.CarMake="23"; |
| car1.CarModel="34"; |
| car1.CarOwner="234"; |
| car1.CarYear=0; |
| car2.CarMake=null; |
| car2.CarModel=null; |
| car2.CarOwner=null; |
| car2.CarYear=0; |
| car3.CarMake=null; |
| car3.CarModel=null; |
| car3.CarOwner=null; |
| car3.CarYear=0; |
| car4.CarMake=null; |
| car4.CarModel=null; |
| car4.CarOwner=null; |
| car4.CarYear=0; |
| car5.CarMake="123"; |
| car5.CarModel="312"; |
| car5.CarOwner="123"; |
| car5.CarYear=0; |
| this.xyz1.Car.Add(car1); |
| this.xyz1.Car.Add(car2); |
| this.xyz1.Car.Add(car3); |
| this.xyz1.Car.Add(car4); |
| this.xyz1.Car.Add(car5); |
| this.xyz1.Location=newSystem.Drawing.Point(424,98); |
| this.xyz1.Name="xyz1"; |
| this.xyz1.Size=newSystem.Drawing.Size(75,23); |
| this.xyz1.TabIndex=0; |
| this.xyz1.Text="xyz1"; |
If you have any doubts, please feel free to let me know.
Best regards,
Bruce Zhou
Please mark the replies as answers if they help and unmark if they don't.