| Skype: | TextControlSupport | |
| Orders: | 877-462-4772 |

| Author: | TX Text Control Support Department |
| Language: | Visual Basic 6.0 |
| Version: | 1.0 |
| Released: | December 16, 2005 |
| Last modified: | January 11, 2008 |
| Requirements: | TX Text Control ActiveX with Visual Basic 6.0 |
| Download code: | tx_resize_table.zip |
Sometimes, you want to insert columns into a table that already exists, but it is not possible to do so, as the table already has the maximum width to fit the page.
The solution is to resize the table automatically, to distribute the available space equally among the columns and to add the new columns afterward. This sample shows you how to do this with TX Text Control ActiveX.
To calculate the new width of each column, the available space (or maximum table width) is calculated and divided by the number of columns present in the table, plus the new columns. Then, the columns are equally resized and the new columns are added. Please note, that the individual size of a column will be lost when using this sample.
Dim newcolumns, i As Integer 'get columns to be inserted newcolumns = Val(cboColumns.Text) Dim width As Integer 'check if the input position is inside a table If Form1.TXTextControl1.TableAtInputPos <> 0 Then 'calculate the new table width including the new columns width = ((Form1.TXTextControl1.PageWidth - Form1.TXTextControl1.PageMarginL - _ Form1.TXTextControl1.PageMarginR) / (Form1.TXTextControl1.TableColumns _ (Form1.TXTextControl1.TableAtInputPos) + newcolumns)) 'set the new table width Form1.TXTextControl1.TableCellAttribute(Form1.TXTextControl1.TableAtInputPos, _ 0, 0, txTableCellHorizontalExt) = width 'check if columns can be inserted If Form1.TXTextControl1.TableCanInsertColumn = True Then 'loop for inserting the new columns For i = 1 To newcolumns 'insert new column (combox index + 1) Form1.TXTextControl1.TableInsertColumn (cboPosition.ListIndex + 1) Next End If End If
The minimum requirements for this sample application are TX Text Control ActiveX trial version and Visual Studio 6.0.