Designer Control Properties

I am using Visual Studio 2005 with C#.  I wrote a user control which has a collection that is exposed through  a property.  When I use the control in the designer, I can then add items to the collection from the properties window.  My problem is that once I recompile, the items are removed from the collection.  What do I need to do in order for the designer to automatically create the code for the items that I add to the collection?
bb3177Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ripahoratiuCommented:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
0
bb3177Author Commented:
 Let me explain a little deeper.  The collection that I need exposed is one that I have implemented.  It is actually just an inherited Collection.Generic.List<type> with some of my own methods added.  The type for that collection is also an object that I have implemented.  The collection already shows up in the designer by default.  Inside of my code, I add several objects to that collection and they show up inside of that collection on the designer as well.  However, it is when I change any of the properties of one of the objects inside of the collection and recompile that the changes do not stick.  I tried using [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] on the collection instantiation inside of the user control and I also tried adding it to each property of the object that the collection takes.  Did I not use this attribute in the correct place?
0
ripahoratiuCommented:
First: You should have exposed a public property (get/set) of the Collection.Generic.List<whatevertype>.
Second: You should set the [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] above that property.

The immediate result should be that, at design time, after you put the control in a form, when you add an item to your collection, the item (its generation code) should appear in Form.Initialize (as the coulmns in ListView as an example). If that doesn't happen than it must be something wrong with your get/set implementations or you're using somewhere an if (DesignMode) or something else.

Try first with a simple  collection to see it work.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

bb3177Author Commented:
I am using the most generic property implementation:
 
        private DataPointCollection DataPoints; //initialized in the Initialize() method of the user control (this)

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public DataPointCollection _DataPoints
        {
            get { return DataPoints; }
            set { DataPoints = value; }
        }

and I have not used any DesignMode type things.

Still no luck.

I have also tried adding Content visibility to each peropery inside of the DataPoint object with no change.
0
ripahoratiuCommented:
Well both of your classes (DataPointCollection and DataPoints) must implement the TypeConverter
MSDN quote
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxdeveloping/html/90373a3f-d8c8-492d-841c-945d62393c56.htm

"Most native data types (Int32, String, enumeration types, and others) have default type converters that provide string-to-value conversions and perform validation checks. The default type converters are in the System.ComponentModel namespace and are named TypeConverterNameConverter. You can extend a type converter when the default functionality is not adequate for your purposes or implement a custom type converter when you define a custom type that does not have an associated type converter."

Than you should also mark your DataPoints class with DesignerSerializationVisibility
0
bb3177Author Commented:
 Here is the current situation.  I have added the attribute

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

to the top of my collection propery.  The result is that the items in the collection get coded in to the designer code for the form that the control is on.  When I make changes in the designer, the changes carry over to the designer code.  The problem comes in after I do a compile.  Once I compile, the changes remain on the designer code.  But, when I open up the collections editor again, it is reinitialized to the original items in the collection (these do not get reappied to the designer code until I press ok).
  It makes no sense to me why this only happens only after a compile.  Another interesting thing I have noted is this.  When similar collections put their items into the designer, each item gets its own section in the designer code.  However, the items in my collection share the same section as the control that the collection belongs to.  So instead of:

//
// item1
//
this.item1.field1 = 0;
this.item1.field2 = 1;


I get

//
// usercontrol1
//
item1.field1 = 0;
item1.field2 = 1;
this.usercontrol.field1 = 0;
...


Note that "this." does not appear with the item in the usercontrol area.
0
ripahoratiuCommented:
Well I cannot imagine what you have there if you don't send the entire code of the properties you want to expose at design time.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.