How do I override TableLayoutPanel.ColumnStyles

T

Tom P.

I'm trying to inherit from a TableLayoutPanel and I want 3 rows and 3
columns. I've tried and tried and I can limit the control to 3x3 but I
can't set the ColumnStyles and RowStyles.

I want them to be AutoSize but they are either editable, in which case
the IDE changes them (all the time). Or they are not editable, in
which case I can't set them to AutoSize.

I'ver tried to hide them using
[Browsable(false), EditorBrowsable
(EditorBrowsableState.Never), ReadOnly(true)]
public new TableLayoutColumnStyleCollection ColumnStyles
{ get; set; }

[Browsable(false), EditorBrowsable
(EditorBrowsableState.Never), ReadOnly(true)]
public new TableLayoutRowStyleCollection RowStyles { get;
set; }

....but then, when I try to put the control on a form I get a "null
object" error when I try to set the ColumnStyles.

this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle
(SizeType.AutoSize));
this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle
(SizeType.AutoSize));
this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle
(SizeType.AutoSize));

this.RowStyles.Add(new System.Windows.Forms.RowStyle
(SizeType.AutoSize));
this.RowStyles.Add(new System.Windows.Forms.RowStyle
(SizeType.AutoSize));
this.RowStyles.Add(new System.Windows.Forms.RowStyle
(SizeType.AutoSize));

I have tried to set the styles before adding controls, after adding
controls, I've read about using the following to set the default
values...
public void ResetColumnStyles()
{
ColumnStyles.Clear();
ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));
}

public bool ShouldSerializeColumnStyles()
{
if (ColumnStyles.Count != 3)
{
return true;
}
else
{
foreach (ColumnStyle CurrentStyle in ColumnStyles)
{
if (CurrentStyle.SizeType != SizeType.AutoSize)
return true;
}
}

return false;
}

....I'm not sure if it even works or not.

I just want the ColumnStyles to be AutoSize and not be able to change.
What do I do?

Tom P.
 

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