We are trying to create a table dynamically in C# code, but the checkbox celltype (the checkmark) is growing big when there is much text in another cell. There is another thread that dicusses the same problem:
http://forum.stimulsoft.com/viewtopic.php?&t=4328
The solution in this thread seems like a hack and complicates the dynamic creation of the table cells a lot. We want to try another and perhaps easier approch, which is to use a image celltype to display checkmark icon for boolean datatypes.
If value for the cell is "true", then simply display an icon of 16x16 pixels and no icon if value is false. However there is no property in the StiTableCell class to set an image to the cell.
The code for generating the table is as follows:
Code: Select all
public static void Print(string headerTitle, DataTable dataTable)
{
var report = new StiReport();
var stream = GetReportFromResources();
report.Load(stream);
//Add data to datastore
report.RegData("listData", dataTable);
report.RegData("metaData", new PrintMetaData { HeaderTitle = headerTitle});
//Fill dictionary
report.Dictionary.Synchronize();
var table = report.GetComponentByName("listTable") as StiTable;
if (table == null) return;
if (dataTable.Columns.Count >= 5)
{
var page = report.Pages[0];
var width = page.Width;
page.Orientation = StiPageOrientation.Landscape;
table.Width += page.Width - width;
}
var headerTemplateCell = table.Components[0] as StiTableCell;
var dataTemplateCell = table.Components[table.Components.Count - 1] as StiTableCell;
table.ColumnCount = dataTable.Columns.Count;
table.RowCount = 2;
table.HeaderRowsCount = 1;
table.FooterRowsCount = 0;
table.DataSourceName = dataTable.TableName;
table.CreateCell();
int indexHeaderCell = 0;
int indexDataCell = table.ColumnCount;
foreach (DataColumn column in dataTable.Columns)
{
//Set text on header
var headerCell = table.Components[indexHeaderCell] as StiTableCell;
headerCell.Text.Value = column.Caption;
SetCellPropertiesFromTemplate(headerCell, headerTemplateCell);
var dataCell = table.Components[indexDataCell] as StiTableCell;
dataCell.Text.Value = "{" + dataTable.TableName + "." + Stimulsoft.Report.CodeDom.StiCodeDomSerializator.ReplaceSymbols(column.ColumnName) + "}";
SetCellPropertiesFromTemplate(dataCell, dataTemplateCell);
if (column.DataType == typeof(bool))
{
dataCell.CellType = StiTablceCellType.CheckBox;
}
indexHeaderCell++;
indexDataCell++;
}
//Render without progress bar
report.Render(false);
report.ShowWithWpf();
}
Can you provide an example of how to set an image to a StiTableCell programmatically?
We are currently running version 2013.3.1800.
Regards
Frode Langeland