Solved

Designer Control Properties

Posted on 2007-03-26
7
183 Views
Last Modified: 2013-12-17
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?
0
Comment
Question by:bb3177
  • 4
  • 3
7 Comments
 
LVL 9

Expert Comment

by:ripahoratiu
ID: 18835830
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
0
 

Author Comment

by:bb3177
ID: 18836244
 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
 
LVL 9

Accepted Solution

by:
ripahoratiu earned 400 total points
ID: 18836603
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:bb3177
ID: 18918986
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
 
LVL 9

Expert Comment

by:ripahoratiu
ID: 18922747
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
 

Author Comment

by:bb3177
ID: 18931376
 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
 
LVL 9

Expert Comment

by:ripahoratiu
ID: 18956620
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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now