Solved

Designer Control Properties

Posted on 2007-03-26
7
180 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

15 Experts available now in Live!

Get 1:1 Help Now