Solved

Designer Control Properties

Posted on 2007-03-26
7
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

738 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