PC Review


Reply
Thread Tools Rate Thread

How do I override TableLayoutPanel.ColumnStyles

 
 
Tom P.
Guest
Posts: n/a
 
      17th Mar 2009
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MDI and TableLayoutPanel vovan Microsoft VB .NET 0 12th Apr 2008 09:35 PM
tableLayoutPanel erik@liffner.se Microsoft Dot NET 0 5th Mar 2006 06:26 AM
Bug in TableLayoutPanel Timothy V Microsoft Dot NET Framework 2 2nd Mar 2006 04:14 AM
VC++ 2005 Beta 2: warning C4490: 'override' : incorrect use of override specifier Adriano Coser Microsoft VC .NET 2 28th Jul 2005 01:54 PM
Adding ColumnStyles to DataGrid Nathan Microsoft VB .NET 7 5th Mar 2005 07:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:17 PM.