Design time property support for a collection

E

Edward Diener

In C++ Builder one could set up a collection of items, by deriving a
collection from TCollection and a collection item from TCollectionItem and
tieing the two together in the derived code, which a user could edit at
design time. This collection had immediate support in C++ Builder's RAD
designer without the programmer having to build any sort of design time
capabilities into his code. It allowed the user to visually add and remove
collection items from a collection as well as set the properties and/or
events for each element in the collection. The collection itself would be a
property of a component and the collection editor would automatically be
applied to that property. Essentially C++ Builder had a built-in design time
collection editor which, needless to say, persisted the collection
information as a propery.

I want to do the same thing in .NET and have a collection, as a property,
which the .NET component designer will allow the end-user to manipulate at
design time by adding and removing items and setting properties and events
on each item. Is there such a facility in the .NET framework ? Is this
facility supported by the typical .NET component designer, such as the ones
in Visual Studio .NET ? If so, what are the steps, or where is the
documentation for creating such a collection of items ?
 
C

Chad Z. Hower aka Kudzu

Edward Diener said:
at design time. This collection had immediate support in C++ Builder's
RAD designer without the programmer having to build any sort of design
time capabilities into his code. It allowed the user to visually add and

Your dreaming. :)

VS.net is a real nightmare for any VCL convert. Any design time component
takes 10 to 100x as much code to make it work. MS still just hasnt "Gotten
it" when it comes to design time component support.
framework ? Is this facility supported by the typical .NET component
designer, such as the ones in Visual Studio .NET ? If so, what are the
steps, or where is the documentation for creating such a collection of
items ?

In nearly all cases, if its not something simple like a string or an integer,
you have to create custom code yourself. And much more than you would with
VCL - its a lot more work to do such simple stuff.

We're considering writing property editors etc for sale, but right now we
have to finish what we are initially working on before we can worry about
packaging them up. :)


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
 
M

Miha Markic

VS.net is a real nightmare for any VCL convert. Any design time component
takes 10 to 100x as much code to make it work. MS still just hasnt "Gotten
it" when it comes to design time component support.

Lucky us that there is C# Builder ;-)
 
E

Edward Diener

I am using Managed C++ so C# Builder does not help in that regard.
However It is hard for me to believe that VS .NET does not have a
property editor for adding and removing items from a collection
property. If, however, it does not, I will have to code my own property
editor.
 
M

Miha Markic

Hi Edward,

I was just sarcastic to Chad.
Of course there is built-it support.
See
CollectionEditor class.

It is applied by default to classes that implement ICollection.

It determines the type of item from Item property (this in C#).

So, you'll have to create a public class MyItem with public get/set
properties.

Create your collection class (possibly by deriving from ArrayList) and
declare Item property to MyItem.

Set your collection property public and voila- there is design time support.

Below is a sample.


--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

public class UserControl1 : System.Windows.Forms.UserControl

{

private MyArrayList al = new MyArrayList();

<snip>

public MyArrayList SomeProperty

{

get

{

return al;

}

set

{

al = value;

}

}

}

public class MyItem

{

private int anInt;

public int MyInt

{

get

{

return anInt;

}

set

{

anInt = value;

}

}

}

public class MyArrayList: ArrayList

{

public virtual MyItem this[int index]

{

get

{

return base[index] as MyItem;

}

set

{

base[index] = value;

}

}

}
 
E

Edward Diener

Thanks for your response. I didn't realize you were being sarcastic to
Chad, but I was very leery of taking his opinion for the truth anyway.

I was thinking of creating my own collection from CollectionBase. This
would allow my collection to be typed to the particular items I want in
my collection. If I do that is there any further functionality I need to
add to my own collection other than the index Item property ? In
particular does my own collection need to implement Add or RemoveAt
functionality in order to get the CollectionEditor to add a new item or
remove an item from the collection ?
 
C

Chad Z. Hower aka Kudzu

Miha Markic said:
Lucky us that there is C# Builder ;-)

Actually I wasnt referencing C# builder. I was speaking about writing
components in VS.net versus writing VCL components in Delphi. VS.net has
gotten a lot better than the older VS's, but its still a TON more code to do
simple editors in VS.net.



--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"


ELKNews - Get your free copy at http://www.atozedsoftware.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top