Page 1 of 1

Dynamic table creation: Set image in a cell programmatically

Posted: Fri Jul 25, 2014 3:02 pm
by lanfro
Hi.

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();
}
This is what we got so far, but we want to replace the section where the celltype is changed to "Checkbox" with a new section that displays an image instead. There is a class named "StiTableCellImage" with a image property, but we can not figure out how to use this.
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

Re: Dynamic table creation: Set image in a cell programmatic

Posted: Mon Jul 28, 2014 7:54 am
by tpontow
Hi,

if you have the Stimulsoft source code option you can see in internal method StiTable.ChangeTableCellContentInImage() how Stimulsoft use StiTableCellImage internally to change StiTableCellCheckBox against an image.

But i think Stimulsoft will send you sample code soon :-)

Kind regards...

Re: Dynamic table creation: Set image in a cell programmatic

Posted: Mon Jul 28, 2014 8:53 am
by HighAley
Hello.

To add image cell you should add StiTableCellImage instad of the StiTableCell.
To show image you could use the Conditions.

We show notice that images could increase using of memory very much. Sometime it cause Out of Memory exception.

Please, use RenderWithWpf() method while you call ShowWithWpf() method.

Thank you.

Re: Dynamic table creation: Set image in a cell programmatic

Posted: Thu Jul 31, 2014 7:39 am
by lanfro
Thanks for the replies and tips :)

However we are still unable to find a solution to this problem and it seems like we are stuck with the nasty growing checkmark when there is a long and wrapped text in another cell. Looked through the documentation and programming manuals provided with the Stimulsoft framework but there were no examples to find. Trying to add a StiTableCell to the table in different ways only resulted in exceptions from the RenderWithWpf() function. Seems like there is no easy solution to this when. Even Stimulsoft support could not provide a code example.

Sorry, I do not know how if we have the Stimulsoft source code option and how to look the source code. But its time to move on now. Currently status is unsolved.

Thank you.

Re: Dynamic table creation: Set image in a cell programmatic

Posted: Fri Aug 01, 2014 6:06 am
by Alex K.
Hello,

Can you please send us a sample project with test data which reproduce the issue for analysis.

Thank you.