Groups | Blog | Home
all groups > dotnet framework > december 2003 >

dotnet framework : Design time property support for a collection


Edward Diener
12/28/2003 9:54:58 PM
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 ?

Edward Diener
12/29/2003 6:22:33 AM
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.



*** Sent via Developersdex http://www.developersdex.com ***
Chad Z. Hower aka Kudzu
12/29/2003 8:24:03 AM
"Edward Diener" <eddielee@tropicsoft.com> wrote in
news:uRr$kcbzDHA.1500@TK2MSFTNGP12.phx.gbl:
[quoted text, click to view]

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.

[quoted text, click to view]

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
Edward Diener
12/29/2003 9:02:34 AM
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 ?


*** Sent via Developersdex http://www.developersdex.com ***
Edward Diener
12/29/2003 11:02:21 AM
CollectionBase implements IList.



*** Sent via Developersdex http://www.developersdex.com ***
Miha Markic
12/29/2003 2:40:56 PM
[quoted text, click to view]

Lucky us that there is C# Builder ;-)

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

Miha Markic
12/29/2003 3:53:30 PM
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;

}

}

}

[quoted text, click to view]

Chad Z. Hower aka Kudzu
12/29/2003 6:08:50 PM
"Miha Markic" <miha at rthand com> wrote in news:#1FIjFhzDHA.556
@TK2MSFTNGP11.phx.gbl:
[quoted text, click to view]

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
Miha Markic
12/29/2003 7:07:12 PM
Hi Edward,

I would say that you need IList implemented.

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

[quoted text, click to view]

AddThis Social Bookmark Button