XRTable in devexpress report with more then 282 rows empties the report - devexpress

If you add more than 282 XRTableRow dynamically into a XRTable, the XRTable and any subsequent contents will not show in the report.

Please note that it is always required to call the XRTable.BeginInit and XRTable.EndInit methods if you modify XRTable.Rows and XRTableRow.Cells collections at runtime.
As for the height of a table, explicitly specify it only if cells' content is not expected to stretch the cells (e.g. this may happen when their CanGrow property is enabled).
public XRTable CreateXRTable() {
int cellsInRow = 3;
int rowsCount = 3;
float rowHeight = 25f;
XRTable table = new XRTable();
table.Borders = DevExpress.XtraPrinting.BorderSide.All;
table.BeginInit();
for (int i = 0; i < rowsCount; i++) {
XRTableRow row = new XRTableRow();
row.HeightF = rowHeight;
for (int j = 0; j < cellsInRow; j++) {
XRTableCell cell = new XRTableCell();
row.Cells.Add(cell);
}
table.Rows.Add(row);
}
table.EndInit();
return table;
}
then add this table to report specific band i,m adding this to Detail band
this.Detail.Controls.Add(CreateXRTable());

Related

Multiple pages in the same PDF reporting with PDFsharp

I am getting values from database and collection of all values are larger than a single page. Number of pages are unknown and it might differ report by report. Currently, only 1 page of multiple pages is being printed but same information in every pages. I want continuous information in the pages not same information in every page. How can I do that with PDFsharp?
Here I am giving my codes to understand...
Document doc = new Document();
//Create table
var sec = doc.AddSection();
var table = sec.AddTable();
table.Format.Font.Size = 6;
table.Borders.Distance = 0;
table.Borders.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray;
var renderer = new DocumentRenderer(doc);
renderer.PrepareDocument();
int totalPage = renderer.FormattedDocument.PageCount;
for (int i = 1; i <= totalPage; ++i)
{
PdfPage pdfPage = pdf.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(pdfPage);
renderer.RenderObject(gfx, XUnit.FromMillimeter(10), XUnit.FromMillimeter(10), XUnit.FromMillimeter(double.MaxValue), table);
gfx.Dispose();
}
You can have MigraDoc create the whole document without a for loop:
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
renderer.Document = document;
renderer.RenderDocument();
Your for loop has a variable i that is not used in your code. If you want to do it the complicated way, use RenderPage instead of RenderObject.
See also:
http://www.pdfsharp.net/wiki/MixMigraDocAndPdfSharp-sample.ashx
I'm not sure if this may be of help to anyone but if you want to break your table into multiple pages you can use this method:
public Document MultiplePagesPerDocument(Document document, DocumentForm documentForm, Section section, DocumentPage page, DataTable dt, int maxTableRows)
{
_document = document;
if (dt.Rows.Count > maxTableRows)
{
for (int i = 1; i <= dt.Rows.Count; i++)
{
// Break the table onto next page for maxTableRows
if (i % maxTableRows == 0)
{
section = _document.LastSection;
section.AddPageBreak();
Paragraph paragraph = section.AddParagraph();
paragraph.Format.SpaceAfter = "3cm";
_position = new PageItemPosition()
{
Height = "3.0cm",
Width = "8.0cm",
Top = "3.0cm",
LeftPosition = ShapePosition.Left,
TopPosition = ShapePosition.Top
};
object tableSection = page.AddPageTextFrame(section, _position, string.Empty);
documentForm.GenerateSection(section, tableSection, 170, "Table", dt);
}
}
}
return this._document;
}

iTextSharp Nest Tables, inner table not 100% width?

I'm using asp.net 4.0 with iTextSharp in it's own class library. From properties, runtime version v2.0.50727, version 5.3.0.0.
When I nest two tables, the inner table has an automatical margin or padding I can't control. How do I get both tables to be 100%?
//edited
public PdfPTable GetHeaderInnerTable(Rectangle pageSize)
{
// create 2 table cell
// left cell for Report Header text
// right cell for microsoft internal only image
int columnCount = 2;
PdfPTable table = new PdfPTable(columnCount);
table.TotalWidth = 792;
//table.WidthPercentage = 100; // 80 is default - THIS IS THE ANSWER TO MAKE INNER TABLE 100%
float[] widthColumns = new float[] { 652, 140 }; //left edge of second column is where image should be
table.SetTotalWidth(widthColumns);
// Left Cell
PdfPCell leftCell = new PdfPCell();
leftCell.Border = 0;
Font font = fontHeaderSegoeUIRegular;
font.Color = BaseColor.WHITE;
Phrase phrase = new Phrase(0, this.PdfModel.CompanyName + Data.Strings_DataResource.PdfTitlePostpend, font);
leftCell.AddElement(phrase);
leftCell.PaddingLeft = 40; // where to start the report name text from the left
leftCell.PaddingTop = 30; // where to start the report name text from the bottom
// Right Cell
PdfPCell rightCell = new PdfPCell();
rightCell.Border = 0;
Image image = Image.GetInstance(this.PdfModel.ImageAssets.Get("HeaderBarRightMicrosoftInternalImageLocation"));
rightCell.FixedHeight = 90; // total height of red bar
rightCell.AddElement(image);
rightCell.Padding = 0;
rightCell.PaddingBottom = 10; // push image up off the red bar
rightCell.BorderWidthRight = 0;
rightCell.PaddingTop = 20; // push image down off the red bar
//// add cells to table
table.AddCell(leftCell);
table.AddCell(rightCell);
return table;
}
public PdfPTable GetHeader(Rectangle pageSize)
{
int columnCount = 1;
PdfPTable table = new PdfPTable(columnCount);
table.DefaultCell.VerticalAlignment = Element.ALIGN_TOP;
table.TotalWidth = pageSize.Width; //792
PdfPCell headerLeftCell = new PdfPCell();
headerLeftCell.Colspan = 1;
float getleft = headerLeftCell.GetLeft(0);
float leading = headerLeftCell.Leading;
headerLeftCell.Padding = 0;
headerLeftCell.PaddingBottom = 0;
headerLeftCell.BorderWidthRight = 0;
headerLeftCell.PaddingTop = 0; // how far donw to print the phrase
headerLeftCell.PaddingLeft = 0; // how far in to print the phrase
headerLeftCell.FixedHeight = this.PixelsToPoints(90); // cell controls height of table
headerLeftCell.Border = 0;
headerLeftCell.Indent = 0;
Image backgroundHeaderImage = iTextSharp.text.Image.GetInstance(this.PdfModel.ImageAssets.Get("HeaderBarImageLocation"));
// assign background Image to cell - 60 instead of 54 because it was gett squashed - probably the padding somehow
headerLeftCell.CellEvent = new BackgroundImageCellEvent(backgroundHeaderImage, 60, 792);
headerLeftCell.AddElement(this.GetHeaderInnerTable(pageSize));
table.AddCell(headerLeftCell);
return table;
}
One answer is to make innertable WidthPercentage 100, where if the value isn't set, it defaults to 80.

AdvancedDataGrid Flex - Row not getting added under correct column

I'm dynamically adding rows and they don't seem to go under the proper column. I have all of my headers in 'headerArray' and the data i need to add is in the string 'item'.
//create an item to work with
var chartItem:Object = new Object();
for( var j:int = 0; j < columnResult.length ; j++ )
{
var item:String = removeformat(removetd(columnResult[j]));
//grab the header (this is which column the value will be added
var head:String = headerArray[j];
//set the value to header (pair)
chartItem[head] = item;
}
//add the chartItem (row) to the main collection
arr.addItem(chartItem);
tableCollection = arr;
It's getting all the headers properly and setting the chartItem (from inspection with debugger). When it gets to a row (building from html) where there is an item that only has values for some of the columns, it doesn't add the information under the right column, it just goes from left to right and adds it in the next one.
The behaviour is kind of strange because the chartItem clearly has the right header value and corresponding item value in it, but like I said they don't end up under the right column.
tableCollection gets set as the dataprovider for the grid later (not modified since)
var chartItem:Object = new Object();
var span:int = 0;
for( var j:int = 0; j < columnResult.length ; j++ )
{
var colSpan:int = this.getColSpan(columnResult[j]);
var item:String = removeformat(removetd(columnResult[j]));
//grab the header (this is which column the value will be added
var head:String;
if (colSpan >1){
head = headerArray[j];
span = colSpan;
} else {
if (span == 0){
head = headerArray[j];
} else {
head = headerArray[j+span-1]
}
}
//set the value to header (pair)
chartItem[head] = item;
}
//add the chartItem (row) to the main collection
arr.addItem(chartItem);
If i read the span attribute for the row, i set the NEXT row to be at column+previous colspan. then all the rows line up properly.

ASP.net problem with changing table row visibility

i have a table array dynamically generated from a data query and stored in a session variable. Now i wanna add a textbox to limit how many rows at a time i will display. To test this, i wrote two button methods, one will set some rows to be visible = false, and the second button method will set the same rows back to visible = true.
protected void limit_btn_Click(object sender, EventArgs e)
{
for (int i = 0; i < traceTables.Length; i++)
for (int j = 2; j < traceTables[i].Rows.Count; j++)
traceTables[i].Rows[j].Visible = false;
Session["Tables"] = traceTables;
table_C();
}//end limit_btn_Click()
protected void obo_btn_Click(object sender, EventArgs e)
{
for (int i = 0; i < traceTables.Length; i++)
for (int j = 2; j < traceTables[i].Rows.Count; j++)
traceTables[i].Rows[j].Visible = true;
Session["Tables"] = traceTables;
table_C();
}//end obo_btn_Click()
protected void table_C()
{
String changeTo = log_locations.SelectedValue;
for (int i = 0; i < sshLoc.Length; i++)
{
if (sshLoc[i].CompareTo(changeTo) == 0)
{
table_panel.ContentTemplateContainer.Controls.Remove(traceTables[currentTable]);
System.Diagnostics.Debug.WriteLine("Removing " + sshLoc[currentTable]);
table_panel.ContentTemplateContainer.Controls.Add(traceTables[i]);
System.Diagnostics.Debug.WriteLine("Adding " + sshLoc[i]);
currentTable = i;
Session["CurrentTable"] = currentTable;
break;
}//end if
}//end for
}//end table_C()
table_C() basically removes and adds the table from the panel - i use it when i want to switch between tables from a dropdown list (which works) and in this case it simply removes and adds the same table from the panel content container.
The problem is that setting the rows to be not visible works fine. Setting the rows back to visible never does, and i'm not sure why
Try using display:none and display:visible rather than .visible in ASP
traceTables[i].Rows[j].Add("style","display:none");
Visible removes it completely from the HTML, so you can only show it again by recreating the page.
You need to store data in a list rather than in a table.
When you set the rows to not visible they are being removed from the html table. That is why you cannot set them to visible again.
If you store the data in a seperate object and bind it to the list, you will be able to turn visibility on and off.

save state of a dataGrid: visible columns, columns width and order

I want to save remotely (on a database) the state (visible columns, columns width and order) of a Flex3 DataGrid.
For width and visibility I can simply save them by accessing each column attribute.. ugly but possible..
But for the order? Do I have to create the dataGrid dynamically??
Any idea is appreciated
thanks
In my case I have saved the order by header name (I'm making an assumption that your DataGrid always has the same columns and header names).
for (var n:Number = 0; n< datagrid.columns.length; n++)
{
var thiscol:DataGridColumn = DataGridColumn(datagrid.columns[n]);
colArray.addItem(thiscol.headerText);
}
Then I can restore the column order by retrieving the ordered list of column headers, and swapping the position of columns in the datagrid as required.
for (var n:Number = 0; n < colArray.length; n++)
{
moveColumnTo(String(colArray.getItemAt(n)), n);
}
I have defined a function moveColumnTo() to perform the switch.
private function moveColumnTo(columnName:String, columnIndex:Number):void
{
// Find current column position
var i:Number = -1;
for (var n:Number = 0; n < datagrid.columns.length; n++)
{
if (DataGridColumn(datagrid.columns[n]).headerText == columnName)
{
i = n;
break;
}
}
if (i == -1 || i == columnIndex) return; // Don't shift column
this.mx_internal::shiftColumns(i, columnIndex); // Shift column to required position
}
Why can't you just save the order as you're looping through each column?
for(var i:int = 0; i < dataGrid.columns.size; i++)
{
var column:DataGridColumn = dataGrid.columns[i];
arr.push({column.visible, column.width, i});
}

Resources