Custom Control

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

I've created a GUI control for my form. It has a public property
that's a generic list. When I use the control on a form, Visual
studio automatically generates the code in InitializeComponents. The
generic list property always gets set null here. How do prevent this
code property from being generated in InitializeComponents?
 
Hi,


How do you want to initialize it?
And to what value?

You could init it in your own class to a new instance and make the property
read only
 
Rick,

Well, it doesn't make much sense that you would expose a setter for the
property that exposes the List. You can expose the List<T> as read only,
(just a getter) and the designer won't try and set the value.

From a design standpoint, it doesn't make sense to allow code outside of
your control replace the entire collection (meaning, the List<T> itself).
Rather, it should just modify elements in that collection.
 
In this case, it's a list of items that I'll be displaying. But the
question applies to any datatype. In some cases, the property might
be a business object of some sort.

Rick,

Well, it doesn't make much sense that you would expose a setter for the
property that exposes the List. You can expose the List<T> as read only,
(just a getter) and the designer won't try and set the value.

From a design standpoint, it doesn't make sense to allow code outside of
your control replace the entire collection (meaning, the List<T> itself).
Rather, it should just modify elements in that collection.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


I've created a GUI control for my form. It has a public property
that's a generic list. When I use the control on a form, Visual
studio automatically generates the code in InitializeComponents. The
generic list property always gets set null here. How do prevent this
code property from being generated in InitializeComponents?
 
Back
Top