{"id":455,"date":"2010-12-21T21:04:48","date_gmt":"2010-12-21T21:04:48","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=455"},"modified":"2026-06-17T09:25:28","modified_gmt":"2026-06-17T08:25:28","slug":"table-layout-panel","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/table-layout-panel\/table-layout-panel","title":{"rendered":"Table Layout Panel"},"content":{"rendered":"<p>Use to make tables and grids which may have any control in each of their cells.<\/p>\n<h4>Making Table Properly Resize On Change Of Contents<\/h4>\n<p>There seems to be an issue with reducing the number of columsn and rows but the TLP scroll bars remaining at the previous<br \/>\nlarger size.  A way to get round this is to simply re-create the whole panel.<\/p>\n<h4>Making a dynamic run time text box based table layout panel<\/h4>\n<p>The following example will work fine as long as you don&#8217;t have too many cells.  Once you start having a large number (10&#8217;s x 10&#8217;s) the<br \/>\nre-creation of the grid can be slow.  If you want lots x lots forget it as its painfully slow and if you get to more than 10000 individual cells you get a &#8220;Error creating window handle&#8221; as windows can only create so many individual window controls.<\/p>\n<h5>At class level define the array of text boxes that will fill the table grid<\/h5>\n<pre><code>\r\n\tprivate: array&lt;System::Windows::Forms::TextBox^, 2&gt;  ^txtGridBoxes;\r\n<\/code><\/pre>\n<h5>This function creates a grid full of the text boxes<\/h5>\n<pre><code>\r\nprivate: void ReDrawGrid (int NumOfColumns, int NumOfRows)\r\n{\r\n\tint Count;\r\n\tint Column;\r\n\tint Row;\r\n\r\n\t\/\/Stop redrawing while we update contents\r\n\tthis-&gt;SuspendLayout();\r\n\tTable1-&gt;Visible = false;\r\n\tTable1-&gt;SuspendLayout();\t\t\/\/Stop painting of the ListBox as items are added\r\n\r\n\t\/\/--------------------------------------------\r\n\t\/\/----- REMOVE THE EXISTING CONTROLS ---------\r\n\t\/\/--------------------------------------------\r\n\tTable1-&gt;Controls-&gt;Clear();\r\n\r\n\t\/\/-----------------------------\r\n\t\/\/----- RE-SIZE THE TABLE -----\r\n\t\/\/-----------------------------\r\n\tTable1-&gt;ColumnStyles-&gt;Clear();\r\n\tTable1-&gt;RowStyles-&gt;Clear();\r\n\r\n\tTable1-&gt;ColumnCount = NumOfColumns;\r\n\tTable1-&gt;RowCount = NumOfRows;\r\n\r\n\tfor (Count = 0; Count &lt; NumOfColumns; Count++)\r\n\t\tTable1-&gt;ColumnStyles-&gt;Add(gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Absolute, 100));\t\/\/Set the width\r\n\r\n\tfor (Count = 0; Count &lt; NumOfRows; Count++)\r\n\t\tTable1-&gt;RowStyles-&gt;Add(gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Absolute, 20));\t\t\t\/\/Set the height\r\n\r\n\t\/\/----------------------------\r\n\t\/\/----- ADD THE CONTROLS -----\r\n\t\/\/----------------------------\r\n\ttxtGridBoxes = gcnew array&lt;System::Windows::Forms::TextBox^, 2&gt;(NumOfColumns, NumOfRows);\r\n\r\n\tfor (Column = 0; Column &lt; NumOfColumns; Column++)\r\n\t{\r\n\t\tfor (Row = 0; Row &lt; NumOfRows; Row++)\r\n\t\t{\r\n\t\t\ttxtGridBoxes[Column, Row] = (gcnew System::Windows::Forms::TextBox());\r\n\t\t\ttxtGridBoxes[Column, Row]-&gt;Margin = System::Windows::Forms::Padding(0, 0, 0, 0);\r\n\t\t\ttxtGridBoxes[Column, Row]-&gt;BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;\r\n\t\t\ttxtGridBoxes[Column, Row]-&gt;Dock = System::Windows::Forms::DockStyle::Fill;\r\n\t\t\ttxtGridBoxes[Column, Row]-&gt;ReadOnly = true;\r\n\t\t\tTable1-&gt;Controls-&gt;Add(txtGridBoxes[Column, Row], Column, Row);\r\n\t\t}\r\n\t}\r\n\r\n\tTable1-&gt;Visible = true;\r\n\tTable1-&gt;ResumeLayout();\r\n\tthis-&gt;ResumeLayout();\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Use to make tables and grids which may have any control in each of their cells. Making Table Properly Resize On Change Of Contents There seems to be an issue with reducing the number of columsn and rows but the TLP scroll bars remaining at the previous larger size. A way to get round this [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58],"tags":[],"class_list":["post-455","post","type-post","status-publish","format-standard","hentry","category-table-layout-panel"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=455"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":456,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/455\/revisions\/456"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}