C# - Passing values in an edit to XtraReport (DevExpress) - c#

I have a XtraReport (DevExpress) in the project, I'm trying to pass a value entered in the editbox (form1) to report the RichBox. How can I do this?
I'm not using any dataset, and only an empty report with some richtextbox.

Solution :
In the tab properties , change the value: xrRichText1 Modifiers = Public
XtraReport1 test = new XtraReport1();
test.xrRichText1.Text = "testing";
//Show Preview
using (ReportPrintTool printTool = new ReportPrintTool(test))
{
printTool.ShowRibbonPreviewDialog();
printTool.ShowRibbonPreviewDialog(UserLookAndFeel.Default);
}

Related

Access stored procedure value within XtraReport

In my Form I have this code to open my report on a click of Button:
private void btnGroupOther_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
LayoutControl lc = new LayoutControl();
lc.Dock = DockStyle.Fill;
DateEdit FirstDate = new DateEdit();
DateEdit LastDate = new DateEdit();
lc.AddItem(Resources.firstdate, FirstDate).TextVisible = true;
lc.AddItem(Resources.seconddate, LastDate).TextVisible = true;
lc.Height = 70;
this.Controls.Add(lc);
this.Dock = DockStyle.Top;
if (DevExpress.XtraEditors.XtraDialog.Show(lc, " ", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
RepProductionGroupOther report = new RepProductionGroupOther();
report.DataSource = paint.RepProductionGroupOther(Convert.ToDateTime(FirstDate.EditValue).ToString("MM/dd/yyyy"),
Convert.ToDateTime(LastDate.EditValue).ToString("MM/dd/yyyy"));
report.ShowRibbonPreviewDialog();
}
}
In my header report I have two xrLabel; the first one txtFirstDate and the second one txtLastDate. I want to show the value of FirstDate DateEdit control in txtFirstDate and the value of LastDate DateEdit control in txtLastDate.
How can I do that, the DataSource of the report is sql stored procedure.
It has two Parameters: #FirstDate and #LastDate.
Thanks in advance
I suggest you to go through XtraReport documentation:
Request and Pass Report Parameter Values
private void button1_Click(object sender, EventArgs e) {
// Create a report instance.
XtraReport1 report = new XtraReport1();
// Obtain a parameter and set its value.
report.Parameters["parameter1"].Value = 30;
// Hide the Parameters' UI from end-users (if you did not hide it at design time).
report.Parameters["parameter1"].Visible = false;
// Show the report's print preview depending on your target platform.
// ...
}
Check the "Custom Parameter Editors" section in above documentation
Custom editor implementation for parameters varies depending on your application's platform:
Windows Forms
In Windows Forms applications, you can provide custom parameter editors in the XtraReport.ParametersRequestBeforeShow event handler.
For a code sample, see Provide Custom Editors for Report Parameters.
Below are similar implementation as you are trying to do.. Check these, hope this will help you resolve the issue.
How to pass parameters to devexpress XtraReport from combobox
DevExpress XtraReport Setting a DateTime Parameter to Today
Passing parameters to Xtrareports repx file

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.

How to retrieve text from a TextBox that was created programatically

Alright, so I have a form set up that contains a label and a button. When the button is pressed it creates several labels and and two textfields in a specific area.
I cannot for the life of me, figure out how to retrieve the text from those textfields and store it in a public string.
Any help would be wonderful and greatly appreciated.
Edit: As per request.
TextBox playertextbox = new TextBox();
playertextbox.Location = new Point(460, 200);
this.Controls.Add(playertextbox);
You can assign a name to the textbox and later use ControlCollection.Find to retrieve it
Try this
TextBox playertextbox = new TextBox();
playertextbox.Location = new Point(460, 200);
playertextbox.Name = "playertxtBox"; // Add some name
this.Controls.Add(playertextbox);
Then use the name in the button click handler or similar :
//Use that name to search here
TextBox playertextbox = ((TextBox) this.Controls.Find("playertxtBox",true)[0]);
string text = playertextbox.Text;

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.

Linking Textboxes to a dataset using a BindingSource

This is the section of the form I am working on:
The following code links the BindingNavigator to the dataset using a bindingSource. Can I use this binding source to hook up the two text boxes to the data?
Do I simply need to use a property of the textboxes or is this more involved?
i.e when the form loads the first record's fields "Work Phrase" and "Description" will be displayed and when I scroll using the navigator the values in these boxes will change accordingly.
public partial class uxRevisionHelperForm : Form
{
public SqlCeConnection conn = new SqlCeConnection(ConfigurationManager.ConnectionStrings["WindFormAppRevisionHelper.Properties.Settings.DefinitionsDBConnectionString"].ConnectionString);
BindingSource definitionsBindingSource = new BindingSource();
public uxRevisionHelperForm()
{
InitializeComponent();
uxDescriptionTextBox.AutoSize = true;
this.hookUpBindingNavigator();
}
public void hookUpBindingNavigator()
{
SqlCeDataAdapter da = new SqlCeDataAdapter(new SqlCeCommand("Select * From tb_Definitions",conn));
DataSet ds = new DataSet("Helper");
ds.Tables.Add("DefinitionsTable");
da.Fill(ds.Tables["DefinitionsTable"]);
// Assign the BindingSource.
this.uxBindingNavigator.BindingSource = this.definitionsBindingSource;
this.definitionsBindingSource.DataSource = ds.Tables["DefinitionsTable"];
}
Try using the DataBinding collection of the textboxes.
Something like this:
uxDescriptionTextBox.DataBindings.Add("Text",
definitionsBindingSource,
fieldInTable);
Have added the full source code (highlighting exactly your requirement) here - http://sdrv.ms/NyXHdu. Download > Open the solution in VS2010 > Hit F5
[Update]
Double click on Form.cs designer and observe the productListBindingSource. It bound to a custom object - The ProductList class
Then see the properties of the TextBoxes & ComboBox and observe the DataBindings > Text property. They are bound to the productListBindingSource's individual item. See Image below.
Courtsey - http://www.apress.com/9781590594391/ [Chapter 8]

Categories

Resources