Telerik Forums
Reporting Forum
1 answer
694 views
I wrote this process to build completely dynamic report based on data which is set of IEnumerable class data from entity framework. it works perfect but I want to render detail section in table, I get empty table. Tried alot but couldn't figure it out.

I could sort and group on multi column, excluded filter since that is done during data fetch. And it is for export only so we don't worry about page size, but if you want to print, use 9 intead of 22 inch as its width.

PS: I don't want to use any report template to start with.

public

 

 

static void GenerateReport(Telerik.ReportViewer.Wpf.ReportViewer rv, IEnumerable<object> data, string extension, SortDescriptorCollection sortDescriptors, GroupDescriptorCollection grpDescriptors

 

 

 

{

 

 

 

Telerik.Reporting.

 

Report report1 = new Telerik.Reporting.Report();

 

report1.DataSource = data;

 

string sortCol = "";

 

string sortDir = "";


 //multi sort can be done by iterating through collection like for group

 

if (sortDescriptors.Count > 0)

{

 

ColumnSortDescriptor sd = sortDescriptors[0] as ColumnSortDescriptor;

sortCol = sd.Column.UniqueName;

sortDir = sd.SortDirection.ToString();

}

 

//Page Header Section

 

 

 

Telerik.Reporting.

 

PageHeaderSection pageHeaderSection1 = new Telerik.Reporting.PageHeaderSection();

 

pageHeaderSection1.Height = 

 

new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType

.Inch);

pageHeaderSection1.Style.BackgroundColor = 

 

Color.Gray;

 

Telerik.Reporting.

 

TextBox txtHead = new Telerik.Reporting.TextBox();

 

txtHead.Value = 

 

"Title";

 

 

 

txtHead.Location = 

 

 

new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(3.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));

 

 txtHead.Name = 

 

"reportTitle";

 

 

 

txtHead.Size = 

 

 

new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch));

pageHeaderSection1.Items.AddRange(

 

new Telerik.Reporting.ReportItemBase[] { txtHead });

 

 

 

IEnumerator dataColl = data.GetEnumerator();

 

int count = 0;

 

 

int

first = 0;

 

 

 

 

object obj = null;

 

 

while (dataColl.MoveNext())

 

 

if (first == 0) 

 

 

{

 

 

 

obj = dataColl.Current;

 

 

 

 

 

foreach (PropertyInfo info in

obj.GetType().GetProperties())

 

{

 count++;

 }

 first++;

 }

}

 

Telerik.Reporting.Drawing. 

 

Unit x = Telerik.Reporting.Drawing.Unit.Inch(0);

 

 

Telerik.Reporting.Drawing.

 

Unit y = Telerik.Reporting.Drawing.Unit.Inch(0);

 

 

Telerik.Reporting.

 

ReportItemBase[] headColumnList = new Telerik.Reporting.ReportItem[count];

 

 

Telerik.Reporting.

 

ReportItemBase[] detailColumnList = new Telerik.Reporting.ReportItem[count];

 

 

Telerik.Reporting.

 

Group group = new Telerik.Reporting.Group();

 

 

 

 

 

 

SizeU size = new SizeU(Telerik.Reporting.Drawing.Unit.Inch((double)(22) / count), Telerik.Reporting.Drawing.Unit.Inch(0.6));

 

 

 

int column = 0;


 

foreach (PropertyInfo info in obj.GetType().GetProperties())  

 

 

{

 

 

 

string columnName = info.Name;

Telerik.Reporting.

 

HtmlTextBox headerCol = CreateTxtHeader(columnName, column);

 

headerCol.Style.BackgroundColor = 

 

Color.LemonChiffon;

 

headerCol.Style.BorderStyle.Default = 

 

BorderType.Solid;

 

headerCol.Style.BorderWidth.Default = 

 

Unit.Pixel(1);

 

headerCol.CanGrow = true;

headerCol.Location = 

 

new Telerik.Reporting.Drawing.PointU(x, y);

 

headerCol.Size = size;

headColumnList[column] = headerCol;

 

 

Telerik.Reporting.

 

TextBox textBox = CreateTxtDetail(columnName, column);

 

textBox.Style.BorderStyle.Default = 

 

BorderType.Solid;

 

textBox.Style.BorderWidth.Default = Unit.Pixel(1);
textBox.CanGrow = true;
textBox.Location = new Telerik.Reporting.Drawing.PointU(x, y);

textBox.Size = size;

 

detailColumnList[column] = textBox;

textBox.ItemDataBinding += 

 

new EventHandler(textBox_ItemDataBound);

 

 

x += Telerik.Reporting.Drawing.

 

Unit.Inch(headerCol.Size.Width.Value);

 

column++;

 

}

 

Telerik.Reporting.

 

ReportItemBase[] groupColumnList = new Telerik.Reporting.ReportItem[grpDescriptors.Count];

 

 

 

 

int i = grpDescriptors.Count;

 

 

 

if (grpDescriptors.Count > 0)

{

 

Telerik.Reporting.

 

GroupHeaderSection groupHeaderSection1 = new Telerik.Reporting.GroupHeaderSection();

 

 

foreach (ColumnGroupDescriptor grpDescriptor in grpDescriptors)

{

 

 

 

string grpCol = grpDescriptor.Column.UniqueName;

group.Groupings.Add(new Telerik.Reporting.Data.Grouping("=Fields." + grpCol));

 

if (grpDescriptor.SortDirection.ToString().ToLower() == "descending")

{

group.Sortings.Add(

 

new Telerik.Reporting.Data.Sorting("=Fields." + grpCol, Telerik.Reporting.Data.SortDirection.Desc));

 

}

 

else

 

 

 

{

group.Sortings.Add(

 

new Telerik.Reporting.Data.Sorting("=Fields." + grpCol, Telerik.Reporting.Data.SortDirection

.Asc));}

 

 

 

 

i--;

 

 

 

Telerik.Reporting.

 

TextBox hdCol = new Telerik.Reporting.TextBox();

 

 

 

hdCol.Style.BackgroundColor = 

 

Color.Orange;

 

hdCol.Style.BorderStyle.Default = BorderType.Solid;
hdCol.Style.BorderWidth.Default = Unit.Pixel(1);

hdCol.KeepTogether = 

 

true;

 

hdCol.Size = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType

.Inch));

hdCol.Value = 

 

"=[" + grpCol + "]"; ;

 

 

groupColumnList[i] = hdCol;

group.GroupHeader = groupHeaderSection1;
//to avoid extra row after group col
group.GroupHeader.Height = Telerik.Reporting.Drawing.

 

Unit.Inch(0);

 

}

 

groupHeaderSection1.Items.AddRange(groupColumnList); 

}

 

 

 

 

 

if

(sortCol.Length > 0)

{

group.Groupings.Add(

 

new Telerik.Reporting.Data.Grouping("=Fields." + sortCol));

 

 

if (sortDir.ToLower() == "descending")

{

group.Sortings.Add(

 

new Telerik.Reporting.Data.Sorting("=Fields." + sortCol, Telerik.Reporting.Data.SortDirection.Desc));

 

}

 

else

 

{

group.Sortings.Add(

 

new Telerik.Reporting.Data.Sorting("=Fields." + sortCol, Telerik.Reporting.Data.SortDirection.Asc));

 

}

 

}

 

 

ReportHeaderSection reportHeaderSection1 = new Telerik.Reporting.ReportHeaderSection();

reportHeaderSection1.Height = 

 

new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType

.Inch);

reportHeaderSection1.Items.AddRange(headColumnList);

report1.Groups.Add(group);

 

 

//Detail Section

 

 

Telerik.Reporting.

 

DetailSection detailSection1 = new Telerik.Reporting.DetailSection();

detailSection1.Height = 

 

new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType

.Inch);

detailSection1.Items.AddRange(detailColumnList);

 

 

 

//Page Footer Section

 

 

Telerik.Reporting.

 

PageFooterSection pageFooterSection1 = new Telerik.Reporting.PageFooterSection();

 

pageFooterSection1.Height = 

 

new Telerik.Reporting.Drawing.Unit(0.3, Telerik.Reporting.Drawing.UnitType

.Inch);

pageFooterSection1.Style.BackgroundColor = 

 

Color.LightGray;

 

 

pageFooterSection1.PrintOnFirstPage = 

 

true;

 

pageFooterSection1.PrintOnLastPage = 

 

true;

 

Telerik.Reporting.TextBox txtFooter = new Telerik.Reporting.TextBox();

txtFooter.Value = 

 

"='Page ' + PageNumber + ' of ' + PageCount";

 

txtFooter.Location = new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(4.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));

txtFooter.Name = 

 

"pageInfoTextBox";

 

txtFooter.Size = 

 

new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(5.5603775978088379D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.20000000298023224D, Telerik.Reporting.Drawing.UnitType.Inch)); Telerik.Reporting.PictureBox picBoxFooter = new Telerik.Reporting.PictureBox();  

 

 

picBoxFooter.Location = 

 

new Telerik.Reporting.Drawing.PointU(new Telerik.Reporting.Drawing.Unit(5.2395832538604736D, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(0.02083333395421505D, Telerik.Reporting.Drawing.UnitType.Inch));

 

 

 

picBoxFooter.Value = 

 

@"C:\CCMSGoldStandard_Local\CCMSGoldStandard\CCMSAppShell\Images\no.png";

 

 

 picBoxFooter.Style.TextAlign = Telerik.Reporting.Drawing.

 

HorizontalAlign.Center;

 

 

 

picBoxFooter.Size = 

 

new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(1, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))), new Telerik.Reporting.Drawing.Unit(.5D, ((Telerik.Reporting.Drawing.UnitType)(Telerik.Reporting.Drawing.UnitType.Inch))));

 

 

 

picBoxFooter.Sizing = 

 

ImageSizeMode.AutoSize;

 

 

 pageFooterSection1.Items.AddRange(

 

new Telerik.Reporting.ReportItemBase[] { txtFooter, picBoxFooter });

 

 

 

//add all section to report

report1.Items.AddRange(

 

new Telerik.Reporting.ReportItemBase[] { pageHeaderSection1, reportHeaderSection1, detailSection1, pageFooterSection1 });

 

 

 

report1.PageSettings.Landscape = 

 

false;

 

report1.PageSettings.Margins.Bottom = 

 

new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Inch);

 

 

 

report1.PageSettings.Margins.Left = 

 

new Telerik.Reporting.Drawing.Unit(.25, Telerik.Reporting.Drawing.UnitType.Inch);

 

 

 

report1.PageSettings.Margins.Right = 

 

new Telerik.Reporting.Drawing.Unit(.25, Telerik.Reporting.Drawing.UnitType.Inch);

 

 

 

report1.PageSettings.Margins.Top = 

 

new Telerik.Reporting.Drawing.Unit(1D, Telerik.Reporting.Drawing.UnitType.Inch);

 

 

 

Telerik.Reporting.Drawing.

 

SizeU paperSize = new Telerik.Reporting.Drawing.SizeU(new Telerik.Reporting.Drawing.Unit(22, Telerik.Reporting.Drawing.UnitType.Inch), new Telerik.Reporting.Drawing.Unit(22, Telerik.Reporting.Drawing.UnitType.Inch));

 

report1.PageSettings.PaperSize = paperSize;

report1.PageSettings.PaperKind = System.Drawing.Printing.

 

PaperKind.Custom;

 

 

 

Hashtable deviceInfo = new Hashtable();

deviceInfo["FontEmbedding"] = "Subset";

 

if (extension.ToLower() == "csv"

)

{

deviceInfo[

 

"NoHeader"] = true;

 

deviceInfo["NoStaticText"] = true;

}

 

Telerik.Reporting.Processing.

 

ReportProcessor RP = new Telerik.Reporting.Processing.ReportProcessor();

 

 

 

 

 

 

 

byte [] buffer = RP.RenderReport(extension.ToUpper(), report1, deviceInfo).DocumentBytes;

 

string myPath = "C:";

 

string file = myPath + @"\" + DateTime.Now.ToString("HHmmss") + "." + extension;

 

 

FileStream fs = new FileStream(file, FileMode.Create);

fs.Write(buffer, 0, buffer.Length);

fs.Flush();

fs.Close();

 

 

 

 

 

Process.Start(file);

 

 

 

 

 

 

}

 

 

 

 

 

static void textBox_ItemDataBound(object sender, EventArgs e)

{

 

if (((Telerik.Reporting.Processing.TextBox)sender).Value == null || (((Telerik.Reporting.Processing.TextBox)sender).Value.ToString() == ""

))

{

((Telerik.Reporting.Processing.

 

TextBox)sender).Value = "";

 

}

 

}

 

 

 

 

 

 

 

public static Telerik.Reporting.HtmlTextBox CreateTxtHeader(string FieldName, int i)

{

Telerik.Reporting.

 

HtmlTextBox txtHead = new Telerik.Reporting.HtmlTextBox();

 

txtHead.Value = FieldName;

 

 

return txtHead;

 

}

 

 

 

 

 

public static Telerik.Reporting.HtmlTextBox CreateHTMLTxtDetail(string FieldName, int i)

{

Telerik.Reporting.

 

HtmlTextBox txtHead = new Telerik.Reporting.HtmlTextBox();

 

txtHead.Value = "=[" + FieldName + "]";

 

//txtHead.Dock = DockStyle.Left;

//txtHead.Name = FieldName;  

 

 

 

txtHead.CanGrow = true;

 

return txtHead;

}

 

 

 

 

 

public static Telerik.Reporting.TextBox CreateTxtDetail(string FieldName, int i)

{

 

Telerik.Reporting.

 

TextBox txtHead = new Telerik.Reporting.TextBox();

 

txtHead.Value = "=[" + FieldName + "]";

txtHead.Name = FieldName;

 

//txtHead.Dock = DockStyle.Left;

//txtHead.CanGrow = true;

return txtHead;

 

 

}

 

Steve
Telerik team
 answered on 19 Apr 2011
4 answers
128 views
Hello, Telerik,

I use telerik reporting, after i set up the Detail Section background image

it's not show on the reporting page,

but after i save as pdf file it is appeared

i use style->backgroundimage->imagedata->then give a "jpg" file from the Resources 

it's WPF reportviewer

please give me an answer and how to fix the problem? thank you

Peter
Telerik team
 answered on 19 Apr 2011
1 answer
472 views
trying to install Telerik Reporting Q1 2011.

And according to the popup when I try to install Net Framework 2.0 since it came as a part of my OS.

How do I manage to install the trial?
Stian
Top achievements
Rank 1
 answered on 19 Apr 2011
1 answer
132 views
Hi,

I developed a report, if I click on the print button on the tool bar, the size of the document is quite big (as I can see from the data been transferred to the printer).

For example, a 1 page report with corsstab, if I exported as a PDF file, it is 167KB, if I directly print it by clicking the print button, it is over 2MB. It seems to me it is sending the report as an image? Even 167KB is still seem quite large for a 1 page report. The worst case is a 160 pages report, when print it by clicking on the print button, the total data size is 16.1GB...

Can someone help with explaining this? It is urgent.

Thank you in advance.

VH

VH
Top achievements
Rank 1
 answered on 19 Apr 2011
1 answer
308 views
Hello
I am working in WPF and have attempted to build a "hello world" report.  i created a simple report using the wizard - no problem.  Then i added a reportviewer to the main xaml page and gave it the name "viewer". 

The xaml is as follows:

 

 

 

<tr:ReportViewer Name="viewer"/>

 



The namepaces that the control added to the page were:

xmlns

 

 

:telerik="http://schemas.telerik.com/2008/xaml/presentation"

 

 

 

 

xmlns:tr="http://schemas.telerik.com/wpf" x:Class="WpfApplication2.MainWindow"

 

 

 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

 

 

 

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

I am getting the error:

 


Could not load type 'Telerik.Reporting.OpenXmlRendering.Presentation.PresentationReport' from assembly
'Telerik.Reporting, Version=5.0.11.316, Culture=neutral, PublicKeyToken=a9d7983dfcc261be'.

References added are:

Telerik.Reporting
Telerik.Reporting.OpenXmlRendering
Telerik.Reporting.Service
Telerik.ReportViewer.Wpf
Telerik.Windows.Controls
Telerik.Windows.Controls.Input
Telerik.WIndows.Controls.Navigation
Telerik.WIndows.Data

Target Framework is .Net Framework 4 (not client)
I am working with Reporting Q1 2011 and RadControls for WPF Q1 2011

The page will not load with the report viewer on it.  It crashes in the InitializeComponent() call of the page.

Of course, the page runs fine if i remove the reportviewer control.

When i search the class view for Presentation.PresentationReport there are no hits, so this file is not anywhere in the references.  What am i missing?

any ideas please?  I always do a very simple test application before moving forward.  I would really like to have this tool work, so i can avoid going back to SSRS for reporitng.

Pam



Steve
Telerik team
 answered on 18 Apr 2011
3 answers
337 views
Hi Telerik,
     I have a Silverlight Report Viewer which uses NeedDataSource to generate vaule for TextBox and bind DataSource of several tables in the report. When viewing the report in Silverlight viewer, all data have been populated correctly. However, the exported PDF (or other format) won't have value in the TextBoxes, but the data in the tables are displayed correctly.

This is how I assign values to TextBox and table's DataSource.
fullName.Value = p.FullName;
educationTable.DataSource = eduList;











The first value is assigned in the Report Viewer but not in exported PDF. The second line works fine in
both Report Viewer and exported PDF.

Do you know if I might miss anything?

Thanks,
Karlkim

Steve
Telerik team
 answered on 18 Apr 2011
4 answers
92 views
I use OA as my datasource quite a bit and thus use NeedsDataSource about 99% of the time.  So I lose all designtime access to show me the Fields Available (the OA DS doesn't always fill the need)

Could you provide some way for me to expose the fields?  Perhaps override or implement an interface somewhere in the code where the designer would get me back those field names that I manually define?

Steve
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
 answered on 18 Apr 2011
3 answers
259 views
Hi

i am using report Q1 2011 , silverlight 4 

not sure what happens .whenever i try to use the Print button on the reportviewer , it always produces a very LARGE file on my printer for printing queue. It is around 160 MB . However if i save the report as PDF (using the Save button on the reportViewer), the file is only around 600KB -2MB. what is going on? with this, i definitely can't use the print button on the report at all  because of large file size queueing for printing 160MB


plz advise

thanks
Steve
Telerik team
 answered on 18 Apr 2011
3 answers
794 views
Forgive me for adding another "blank pages" item to the support log but I think I have a different example of when this happens from what I'm seeing.

This is in Q1 2011 that I'm seeing this.

I have a table of items which could take more than 1 page to print out.  When I have more than 1 page worth of columns and I print the report by itself, everything works nicely.  When I embed the report as a subreport in another master report, as long as it's the only subreport, it prints OK.  When I embed a second subreport on the same master report, it starts printing 1 blank page for every extra page the table prints to (i.e, if the table needs 2 pages to print, it puts 1 blank page at the end of the master report, if it needs 3 pages, there are 2 blank pages at the end of the report).

I can make each report invisible and the report draws without any blank pages but as soon as the table is visible with any other subreport, it adds blank pages.

I thought I could get around this by using the ReportBook class to just combine multiple reports together, but the blank pages then become the table sub report and which ever report is second.

I have used the suggestions for finding which subreport could be flowing onto extra pages but the only thing it tells me is the detail section for the master report (where my subreports live) is flowing onto the blank last pages.

It looks like having multiple subreports in the detail section, 1 of which could maybe flow to multiple pages, causes some problems for planning how to draw each page.

Is there any way to correct this or figure out what I might be doing to cause the reporting engine to work this way?

Thanks in advance!
Charles Rosecrans, Jr.
Top achievements
Rank 2
 answered on 16 Apr 2011
2 answers
103 views
Is there a way to unit test reports?  To make sure they all render without errors?

Steve
sitefinitysteve
Top achievements
Rank 2
Iron
Iron
Veteran
 answered on 15 Apr 2011
Top users last month
Cynthia
Top achievements
Rank 1
Iron
Toby
Top achievements
Rank 3
Iron
Iron
Iron
Danielle
Top achievements
Rank 1
Iron
Iron
Joel
Top achievements
Rank 3
Bronze
Bronze
Iron
yw
Top achievements
Rank 2
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?