[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Designer Control Properties

Posted on 2007-03-26
7
Medium Priority
?
193 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 1600 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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