title: Synchronising TableLayoutPanels
body: <p>I have several TableLayoutPanels, each of which displays a category of name/value information in two columns - one with informational labels, and one with data labels.</p>
  
  <p>In each one, I've set the first column to autosize and right-aligned all the labels, which works just fine. However, it works separately to each TableLayoutPanel (obviously), and looks something like this:</p>
  
  <pre><code>TableLayoutPanel 1:
  
  +--------+--------+
  | Name 1 | Data 1 |
  +--------+--------+
  | Name 2 | Data 2 |
  +--------+--------+
  | Name 3 | Data 3 |
  +--------+--------+
  
  TableLayoutPanel 2:
  
  +------------------+--------+
  |      Long Name 1 | Data 1 |
  +------------------+--------+
  | Very Long Name 2 | Data 2 |
  +------------------+--------+
  |      Long Name 3 | Data 3 |
  +------------------+--------+
  </code></pre>
  
  <p>I'm looking for a way to consider <i>all</i> of the name labels when autosizing <i>all</i> of the first columns, so it looks like this:</p>
  
  <pre><code>TableLayoutPanel 1:
  
  +------------------+--------+
  |           Name 1 | Data 1 |
  +------------------+--------+
  |           Name 2 | Data 2 |
  +------------------+--------+
  |           Name 3 | Data 3 |
  +------------------+--------+
  
  TableLayoutPanel 2:
  
  +------------------+--------+
  |      Long Name 1 | Data 1 |
  +------------------+--------+
  | Very Long Name 2 | Data 2 |
  +------------------+--------+
  |      Long Name 3 | Data 3 |
  +------------------+--------+
  </code></pre>
  
  <p>I can't put all the data into one table, because each table represents a different category of information, and is inside a custom control with a collection of collapsible panels (so you can show or hide each category separately).</p>
  
  <p>I've been trying to achieve this by overriding the container controls OnLayout(), setting all of the TableLayoutPanels' first columns to autosize, getting all of their widths, finding the maximum, and then settings all of their first columns to a fixed size of the greatest width. This works, but looks horrible every time layout occurs as all the columns jump to autosize and then back to fixed size.</p>
  
  <p>I'm assuming I'm going to have to hook ControlAdded and ControlRemoved for each table, and then SizeChanged for each child control, to know when the size of any child control changed, and then manually set the column width somehow, but I'm not sure how to reliably get the correct widths. </p>
  
  <p>I tried a variation of the first method - using GetPreferredSize() on all the controls in the first columns, to attempt to find the largest width, and then setting all first columns to a fixed size, but it seemed to return widths that were slightly to small. Should I be applying some extra spacing?</p>
  
  <p>Does anyone know any way of asking the TableLayoutPanel to perform autosize calculations without it actually applying them visually? Or perhaps, lying to the tables to 'pretend' that there is a control of a certain width, just so it takes it into account? I can't add actual controls, since it will then want to allocate more cells for them. I tried looking at the source with ILSpy, but well, it isn't pretty. Seems most of the work is done by TableLayout class, which is, of course, internal, and I couldn't follow what it was doing.</p>
  
  <p>Thanks for any ideas...</p>