Control initialisation

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm not sure what to make of this problem, but hopefully it's fixable. I have
created a 'Table' control which is basically just a grid of text boxes.
However, whenever the control is initialised it is done so in the wrong order:

this.table1.Columns = 3;
this.table1.DefaultColumnWidth = 96;
this.table1.DefaultRowHeight = 22;
this.table1.Rows = 3;

That is an extract from a form's InitializeComponent function. As should be
able to see the table columns are created before the default column width is
specified when it really should be done beforehand. Is there any way to force
the designer to initialise the properties of a control in a specific order as
opposed to alphabetic?

Thanks in advance
 
Barguast,

AFAIK, there is no way to change this. Classes in general should not
force properties to be set in a specific order, it's just bad design. If
you require all of this information, then you should have a method that
takes everything at once, and performs the operation.

In this case, you will have to make your control adaptable so that it
can react to changes in any of the properties that affect the appearance of
the control. So, when the columns change, you add a new column.

You should probably change the property names to ColumnWidth and
RowHeight. This way, when they are changed, all of the items on the control
change (after all, that is the effect you want).

Hope this helps.
 
I'm not sure what to make of this problem, but hopefully it's fixable. I have
created a 'Table' control which is basically just a grid of text boxes.
However, whenever the control is initialised it is done so in the wrong order:

this.table1.Columns = 3;
this.table1.DefaultColumnWidth = 96;
this.table1.DefaultRowHeight = 22;
this.table1.Rows = 3;

That is an extract from a form's InitializeComponent function. As should be
able to see the table columns are created before the default column width is
specified when it really should be done beforehand. Is there any way to force
the designer to initialise the properties of a control in a specific order as
opposed to alphabetic?

Thanks in advance

Without seeing your code, I'm assuming you have some 'side effects' in
your property setters.

Look at the System.ComponentModel.ISupportInitialize documentation. It
will let you know when your control is starting to be initialized and
when it is done being initialized.
 
I wasn't too sure about it myself either. I'd probably be best if I had an
array of column width / row heights values rather than a 'default' - that'd
also let you specify the size of each individual row / column rather than
restricting them all to be the same.

Thanks for the speedy response ;)

Nicholas Paldino said:
Barguast,

AFAIK, there is no way to change this. Classes in general should not
force properties to be set in a specific order, it's just bad design. If
you require all of this information, then you should have a method that
takes everything at once, and performs the operation.

In this case, you will have to make your control adaptable so that it
can react to changes in any of the properties that affect the appearance of
the control. So, when the columns change, you add a new column.

You should probably change the property names to ColumnWidth and
RowHeight. This way, when they are changed, all of the items on the control
change (after all, that is the effect you want).

Hope this helps.


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

Barguast said:
I'm not sure what to make of this problem, but hopefully it's fixable. I
have
created a 'Table' control which is basically just a grid of text boxes.
However, whenever the control is initialised it is done so in the wrong
order:

this.table1.Columns = 3;
this.table1.DefaultColumnWidth = 96;
this.table1.DefaultRowHeight = 22;
this.table1.Rows = 3;

That is an extract from a form's InitializeComponent function. As should
be
able to see the table columns are created before the default column width
is
specified when it really should be done beforehand. Is there any way to
force
the designer to initialise the properties of a control in a specific order
as
opposed to alphabetic?

Thanks in advance
 
Back
Top