views:

14

answers:

1

I'm trying to build a table layout similar to this

 ---------------------------------------------------------------------
|   01.01.2010 01:00   |   01.01.2010 01:00   |   01.01.2010 01:00    |
 ---------------------------------------------------------------------
|   Some text       |  More            | And         | Final text     |
|   (Multilined)    |  multilined      | more text   | Multiple lines,|
|                   |  text            |             | too            |
 ---------------------------------------------------------------------

It has to be created dynamically, so I can't create it in the Form Designer...

The first approach was as followed

// The "outer" table - two rows (the dates and the texts)
TableLayoutPanel table = new TableLayoutPanel();
table.ColumnCount = 1;
table.RowCount = 2;

// Date table - three columns
TableLayoutPanel dateTable = new TableLayoutPanel();
dateTable.ColumnCount = 3;
dateTable.RowCount = 1;

// Text table - four columns
TableLayoutPanel textTable = new TableLayoutPanel();
textTable.ColumnCount = 4;
textTable.RowCount = 1;

// Add it all up and save it to the panel in the winform
table.Controls.Add(dateTable);
table.Controls.Add(textTable);
SomeUIPanel.Controls.Add(table);

It seems to work, as I get no exceptions - but it looks horrible. The width of the table is too short, the text columns are not added in the way I described above and I also have the feeling, that the table is too short in height as some texts are cut off at the bottom.

Any better approaches to this? Or helpful tutorials regarding these matters?

+1  A: 

I think you have the right structure. What I don't see is any Width/Height/Docking/Anchoring.

I would add:

table.Dock = DockStyle.Fill;
dateTable.Dock = DockStyle.Top; 
textTable.Dock = DockStyle.Fill;
Henk Holterman
Perfect - but now there are two other questions; How can I adjust the height of the table to fit its content? Now, the Table fills the whole Panel - but I want it to have the size its content needs. Secondly, the date table i left aligned, how can I make it to match the example above, so all dates are centered and the column widths are all the same?
ApoY2k
Apo, I don't have all the answers but you can make the main table Dock=Top and AutoSize, TextAlignment is up to the Label controls.
Henk Holterman