Search This Blog

Sunday, November 6, 2016

                          Table and Table operation in Tx Text Control

   Table is a graphical view with number of row and column. It is a important part of a report to show data in tabular. It is very easy to add a table to a report by GUI but not too easy with program with define number of row at run time. Tx Text Control provide various control over table and it operation like merge cell, next level table and text format in table cells. Generally generate table dynamically, we have information about columns but don't have information about rows in a table.

  In Tx Text Control, all tables in a report have a unique id which start from 10. we can access and modify any table and table items by getting table information through its id. A next level table means table new table with different table id insert in a table cell or you can say a table cell have a new table itself. Hare, I am explaining how to create dynamic tables and with fix number of columns and unfixed number of rows.

For example:

var tx = new ServerTextControl();
tx.Tables.Add(2, 2, 11);//tx.Tables.Add(numberOfRow, numberOfColumn, uniqueTableID)
TXTextControl.Table table = tx.Tables.GetItem(tableID);
table.Cells.GetItem(1, 1).Width = 300;
table.Cells.GetItem(2, 1).Width = 300;
tx.Selection.Start = table.Cells.GetItem(1, 1).Start - 1;
tx.Selection.Length = table.Cells.GetItem(2, 2).Length;
tx.Selection.ParagraphFormat.Alignment = alignment;
tx.Selection.ParagraphFormat.TopDistance = 0;
tx.Selection.Bold = boldFlag;
int BottomTextDistance = 10;
int TopTextDistance = 10;
table.Cells.GetItem(1, 1).CellFormat.BottomTextDistance = BottomTextDistance;
table.Cells.GetItem(1, 1).CellFormat.TopTextDistance = TopTextDistance;
table.Cells.GetItem(1, 1).Text = "Name";
table.Cells.GetItem(1, 2).Text = "Value";
table.Cells.GetItem(2, 1).Text = "Durgesh";
table.Cells.GetItem(2, 2).Text = "Software Engineer";
tx.Selection.FontSize = 220;

public void SetCellFormat(TXTextControl.Table table)
            for (int row = 1; row <= table.Rows.Count; row++)
                for (int col = 1; col <= table.Columns.Count; col++)
                    //if (row == 1 && col > 1)
                    //else if (row > 1 && col > 1)
                    table.Cells.GetItem(row, col).CellFormat.TopBorderWidth = 1;
                    table.Cells.GetItem(row, col).CellFormat.BottomBorderWidth = 1;
                    table.Cells.GetItem(row, col).CellFormat.LeftBorderWidth = 1;
                    table.Cells.GetItem(row, col).CellFormat.RightBorderWidth = 1;

Code of dynamic table

Output of above code

  • Dynamically add row above or below the current row :
    table.Rows.Add(TableAddPosition.After, CuurentRowPossision);
    table.Rows.Add(TableAddPosition.Before, 1);

No comments:

Post a Comment