Visual Studio ReportViewer Control - c#

I'm trying to use the ReportViewer Control in Visual Studio 2008 but I'm having problems with viewing the "Smart Tag Panel". The little triangle which should be in the top right corner is not shown. I think the problem is that I can't select the ReportViewer in the Designer in Visual Studio. How do I fix this?
Otherwise i tried to sholved the problem by filling the ReportViewer with data programatically but i also have some problems here. I get an message, which is shown inside the ReportViewer at rumtime:
A datasouce instance have not been supplied for the data source ...
I'm using this code:
private void LoadEmployeeTimeregistrations(string employeeNumber)
{
_employeeTimeregistrations = new List<TimeregistrationData>();
EntityCollection<TimeregistrationsEntity> employeeTimeregList =
_client.TimeRegistrations().GetTimeregistrations(
KRWindPcClassesLibrary.Properties.Settings.Default.ProjectNumber,
employeeNumber, false, null);
if (employeeTimeregList != null)
{
foreach (var timereg in employeeTimeregList)
{
_employeeTimeregistrations.Add(new TimeregistrationData
{
Day = timereg.Time.ToShortDateString(),
TotalHoursPresentation = 8.ToString()
});
}
}
ReportDataSource reportDataSource = new ReportDataSource("Data", _employeeTimeregistrations);
reportViewer2.LocalReport.DataSources.Clear();
reportViewer2.LocalReport.DataSources.Add(reportDataSource);
reportViewer2.LocalReport.Refresh();
reportViewer2.RefreshReport();
}

See this website:
http://www.gotreportviewer.com/
It should have all of the information that you require regarding setting a datasource (amongst many, many other things) for the ReportViewer for VS 2008.

Related

RDLC Reporting using C#

I am completely new to reporting in visual studio C#..I tried searching for some tutorials for beginners but i was unsuccessful..I just found code examples that didn't really explain the basics...I wrote some code which complies and runs fine but it DOES NOT SHOW ANYTHING in the report viewer control in Visual Studio 2013..My code is as follows:
// This method is in a class named Customers.
// When the user clicks the first column of the datagrid view(I have placed a button
// in the first column of the datagrid) a new form opens (ReportForm) and i pass
// the DataSet called dsReport to its constructor.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0 )
{
DataSet dsReport = new DataSet();
DataTable tbl = dsReport.Tables.Add();
tbl.Columns.Add("CustomerName", typeof(string));
tbl.Columns.Add("CustomerAddress", typeof(string));
tbl.Columns.Add("MaritalStatus", typeof(string));
tbl.Columns.Add("CustomerType", typeof(string));
tbl.Columns.Add("ImagePath", typeof(string));
foreach (Customer cust in customerList)
{
DataRow dr = dsReport.Tables[0].NewRow();
dr["CustomerName"] = cust.Name;
dr["CustomerAddress"] = cust.Address;
dr["MaritalStatus"] = cust.MaritalStatus;
dr["CustomerType"] = cust.CustomerType;
dr["ImagePath"] = cust.ImagePath;
dsReport.Tables[0].Rows.Add(dr);
}
ReportForm report = new ReportForm(dsReport);
report.Show();
}
}
//Following is the code for the ReportForm Class
//I do not get any results in the report viewer
//I just see the message "The source of the report definition has not been specified"
public ReportForm(DataSet dsReport)
{
InitializeComponent();
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(myReportSource);
this.reportViewer1.ProcessingMode = ProcessingMode.Local;
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
}
private void ReportForm_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
/* Please note that I have run the code in the debugger and the dataset is being
populated properly and so is the reportViewer1.LocalReport..Also I HAVE NOT
Added any datasources to the project AND I HAVE NOT ADDED ANY Report files(.rdl) files
to the Project */
Lastly can anyone PLEASE answer the following questions:
Q1. Do i absolutely have to include a datasource to work with the report
viewer tool??
Q2. Do i have to include a .rdl file in the project to display a report??
Q3. Is the report viewer tool and a .rdl file one in the same or are they
different??
The ReportViewer is a control that knows how to render a report. It just handles the drawing and some other background tasks, it isn't the actual report. The actual report is the .rdl file (Report Definition Language). It contains all the instructions for generating the report, but it doesn't contain the actual data. The DataSource contains the data that the report operates on.
So to answer your questions specifically:
yes (unless your report is completely static and doesn't use any data).
no, but you need get the .rdl to the ReportViewer somehow. If you don't want to include it as a file you can embed it as a resource in your application, or even hard code it as a string. The ReportViewer has a method that accepts a Stream also, so anything that can provide a stream can act as the source for the .rdl.
They are different, as I explained at the very start.

How to set a XtraReport into a GroupPanel in Winforms Devexpress?

I created a Form and place GroupPanel in that Form now I created XtraReports and I tried to set that XtraReports in to that GroupPanel of that Form. I tried this code but showing error Best Overloaded method has some invalid arguments
GroupPanel1.Controls.Clear();
XtraReport1 report = new XtraReport1 ();
ReportPrintTool tool = new ReportPrintTool(report);
GroupPanel1.Controls.Add(report); // showing error on this line
report.ShowPreview();
This code is working fine for set a Form2 inside that GroupPanel1 of Form1
panelControl1.Controls.Clear();
var myForm = new ListEmployee(id);
myForm.TopLevel = false;
myForm.AutoScroll = true;
myForm.Anchor = panelControl1.Anchor;
panelControl1.Controls.Add(myForm);
myForm.Show();
Help me to solve this. How to set XtraReports into GroupPanel ?
Thanks in avance, Srihari
If you want to show preview for report you need to use DocumentViewer control:
GroupPanel1.Controls.Clear();
var viewer = new DocumentViewer(); //using DevExpress.XtraPrinting.Preview
viewer.Dock = DockStyle.Fill;
GroupPanel1.Controls.Add(viewer);
var report = new XtraReport1();
viewer.DocumentSource = report;
report.CreateDocument();
If you want to show designer for report you neet to use XRDesignPanel control:
GroupPanel1.Controls.Clear();
var designer = new XRDesignPanel(); //using DevExpress.XtraReports.UserDesigner
designer.Dock = DockStyle.Fill;
GroupPanel1.Controls.Add(designer);
var report = new XtraReport1();
designer.OpenReport(report);
GroupPanel1.Controls.Add() takes as argument an instance of an object descended from the Control class. Since the XtraReport class is noct descended from the Control class you cannot add an XtraReport to a GroupPanel or any other element on a winform.
If you only want to show the output of the report in the panel you could export the report to one of the supported formats.
Since you allready use DevExpress XtraReports you could use ExportToRtf() if you have access to the DevExpress RichEditControl.

Child Control is not rendering

I created a custom composite control that contains, among other things, child controls from this project https://googlevisnet.codeplex.com/ (it is a .NET library for google charts which i checked various times). I am using VisualStudio 2012 and a simple C# Class library.
I override CreateChildControl like so:
protected override void CreateChildControls()
{
Controls.Clear();
//create the pie control
GenderChart = new GVPieChart();
GenderChart.Width = PieChartDimentions[0];
GenderChart.Height = PieChartDimentions[1];
GenderChart.ChartData(GenderDistributionTable);
//create the bar control
AgeChart = new GVColumnChart();
AgeChart.Width = BarChartDimentions[0];
AgeChart.Height = BarChartDimentions[1];
AgeChart.ChartData(AgeDistributionTable);
this.Controls.Add(GenderChart);
this.Controls.Add(AgeChart);
}
and override Render like so:
AgeChart.RenderControl(output);
When I run the code on the page everything seems to work, and i can tell that the control rendered the area correctly (i can see the div with the specific size), however I do not see the chart itself.
The weird thing is that for a moment there it was working and then stopped again without me applying any changes to the code.
Any Ideas?
Apparently what solve the problem was something as stupid as adding the ID for the controls.
protected override void CreateChildControls()
{
Controls.Clear();
//create the pie control
GenderChart = new GVPieChart();
GenderChart.ID = "genderChar";
GenderChart.Width = PieChartDimentions[0];
GenderChart.Height = PieChartDimentions[1];
GenderChart.ChartData(GenderDistributionTable);
////create the bar control
AgeChart = new GVColumnChart();
AgeChart.ID = "ageChart";
AgeChart.Width = BarChartDimentions[0];
AgeChart.Height = BarChartDimentions[1];
AgeChart.ChartData(AgeDistributionTable);
this.Controls.Add(GenderChart);
this.Controls.Add(AgeChart);
}
I don't know how i forgot something as essential as ID. Our mind stops to think simple at some point.
Cheers :)

Adding a new property to a control which opens a new form?

We have a report designer project which uses Active Reports.
We want to use SubReport tool of the Active Reports.
Subreport control has a "report" property which fills the ActiveReport content of the Subreport.
Since we have a designer project and a SubReport tool,
I want to add a property to the SubReport control which opens a new form that enables user to choose a report from the list and load report into the SubReport control.
So how can I add a property to a control which opens a new windows form?
Here is how I set the properties:
public class SubReportProp
{
private DataDynamics.ActiveReports.SubReport _SubReport;
public SubReportProp(DataDynamics.ActiveReports.SubReport subReport, List<string> fieldCollection)
{
this._SubReport = subReport;
if (fieldCollection != null && fieldCollection.Count > 0)
{
FieldVars._DataFields = fieldCollection;
}
}
[DisplayName("X")]
[Description("Kontrolün yatay konumunu getirir veya ayarlar.")]
[Category("Konum")]
public float X
{
get
{
return SharedProp.TrimFloatValue(ActiveReport.InchToCm(_SubReport.Location.X));
}
set
{
_SubReport.Location = new PointF(ActiveReport.CmToInch(value), _SubReport.Location.Y);
}
}
[DisplayName("Y")]
[Description("Kontrolün dikey konumunu getirir veya ayarlar.")]
[Category("Konum")]
public float Y
{
get
{
return SharedProp.TrimFloatValue(ActiveReport.InchToCm(_SubReport.Location.Y));
}
set
{
_SubReport.Location = new PointF(_SubReport.Location.X, ActiveReport.CmToInch(value));
}
}
}
Like these x, y coordinates I also need to add another property which enables user to choose a report from a list and apply to _SubReport.Report
http://blogs.gcpowertools.co.in/2011/11/showcase-enhance-end-user-designer.html#more
I think you should have a look at this blog . It does exactly what you want.
kubilay
Report layout can be saved to stream. You can save this to the database as a blob/byte array. You can also save the report in its xml format as text, if possible. This is accomplished using the ActiveReport's SaveLayout API.
LoadLayout API can then be used to load this report back.

Problem in adding user controls to toolbox programatically

Hi
I'm trying to add a new tab and my controls programatically to visual studio 2010.
Its creating tab but its not adding the controls to tab.
//Getting design time environment
DTE DesignTimeEnvironment = (DTE)Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.DTE.10.0"), true);
//Getting tool box object
ToolBox VSToolBox = (ToolBox)DesignTimeEnvironment.Windows.Item("{B1E99781-AB81-11D0-B683-00AA00A3EE26}").Object;
ToolBoxTab MyTab = null;
string TabName = "MyComponents";
//checkin if Tab already exists
foreach (ToolBoxTab VSTab in VSToolBox.ToolBoxTabs)
{
if (VSTab.Name == TabName)
{
MyTab = VSTab;
break;
}
}
//If tab doesn't exist, creating new one
if (null == MyTab)
MyTab = VSToolBox.ToolBoxTabs.Add(TabName);
MyTab.Activate();
ToolBoxItem tbi = MyTab.ToolBoxItems.Add("FileBrowser",
#"MyComponents.FileBrowser, MyTestComps, Version=1.0.0.1, Culture=neutral, PublicKeyToken=2283de3658476795",
vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
DesignTimeEnvironment.Quit();
If i run as administrator its working fine, adding Controls to control library,
but when I try to add the library which is not in GAC its not working. It doesn't through any exception.
Ex:
ToolBoxItem tbi = MyTab.ToolBoxItems.Add("FileBrowser",
#"C:\MyComponents\MyTestComps.dll",
vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
It is working fine with the above code.
The only problem was I have to run the application as administrator rights.
Even this way also it is working.
ToolBoxItem tbi = MyTab.ToolBoxItems.Add("FileBrowser",
#"C:\MyComponents\MyTestComps.dll",
vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);
or
http://blogs.msdn.com/b/quanto/archive/2009/06/12/how-do-i-deploy-a-toolbox-control-as-a-vsix.aspx

Categories

Resources