How to change the subreport source in a run time? - c#

I'm creating some report in C# and I have 2 types of them. The header and footer are the same but the middle part is different. I have a type parameter to determine which type report is it. But I don't know how to change the source subreport. The field "Use this report as subreport" unfortunately doesn't allow to enter the expression so I cannot define the necessary report by condition. And I don't know how to do that from the code.

I've found the solution. Just put 2 different subreports on the main report and use expression to determine which one should be shown, which - to be hidden. Stupid but works.

Related

Generate Subreport on each Report page

Good people!
I am trying to add a subreport to the main report and it must be repeated on each page. I already try to put the "RepeatWith", but it is not allowed to subreport.
Also try to add it as header to the "tablix", with the "RepeatOnNewPage", but it repeats it without regenerating the information (DataSet) of the subreport itself, leaving literally the same.(Because I take it as "Static")
Any other idea?

Crystal Reports:Hide/suppress field in report depending on user input/parameter

So I have attached a picture of my app below. What I have is a Winforms C# app where the user can generate a barcode. He enters the parameters on the left, clicks Generate, and the Crystal Report is shown on the right with the barcode in a 4x12 format. I created the report template manually, i.e added Blob fields on the report in the positions I wanted through trial and error, and when the user clicks generate, it simply passes the image to the report.
I plan on adding a facility where the user can choose which slots on the report to actually generate an image, because perhaps he doesn't want to print 48 barcodes at a time. So maybe a checkboxes or something where the user will determine at runtime how the report will generate.
So my question is, what is the best way to do this? I was thinking of passing a list of the desired slots to the report as a parameter, and hiding or suppressing the fields depending on the list, but I don't know how to do this. My Crystal reports knowledge isn't the greatest. I only found ways to suppress data in cases of duplicate data, but I have a somewhat unique case where there isn't much info out there.
to suppress an item using some condition I do it as follow:
select the item (that could be suppressed based on the condition)
right click on the item
select "Format Field" or "Format Text"
in the tab menu select "Common"
in the common tab look for Suppress (it is a checkbox) and check it the click on the button that have a x+2 and a pencil,
write your condition
you may do it the other way around (unchecked textbox and condition to hide)
an example of mine: (?official is a parameter I sent)
IF {?Official} = true THEN
true
ELSE
false

How can I set Report Viewer language the same as CultureInfo.CurrentUICulture?

As I understood, by default, the language of report viewer is set by "CultureInfo.InstalledUICulture" (not that simple). That means, if my computer is from Brazil, then it will format numbers with Brazil's culture. Altought my data may be formatted with United States' culture, so my report viewer display things incorrectly. I guess one solution to solve it, is by changing the language of the report viewer as the same of my CultureInfo.CurrentUICulture.
How can I achieve that in the simplest way, please?
In the report properties set the Language property as:
=System.Threading.Thread.CurrentThread.CurrentUICulture.ToString()
Or to whatever you need. I'm using a report parameter for example. The value must resolve to a string.
You can access the report properties via the properties window, and then from the top list select "Report". Or you could simply click in the gray area of the report, and press F4.
.
There are two (+1) separate things here:
The language of the controls, tooltips, etc. inside the ReportViewer control. This depends on the System.Threading.Thread.CurrentThread.CurrentUICulture.
The number, date, currency, etc. formats within the report. These are controlled by changing the Language property of the rdlc file in use.
The actual content of the report which is controlled via your DataSource(s). This one is pretty obvious, but I mentioned it for sake of completeness.

Using Crystal reports to generate ID card dynamically

i want to generate an ID card for various group members belonging to different section. Each has a different format depending on what user selects e.g
What i also want is the photo portion should be adjustable in the area where the user wants to amd also the photo that comes from database should be able to crop as per the user requirements.
Is this possible doing using Crystal Reports.Any tutorials and guidelines will be helpful as i am absolutely new to using Crystal Reports.
If not using=Crystal Reports,what is the other best option.
Please help me to get the ID card to be generated dynamically.
If you wanted to narrow it down to just one report you could something similar to what MD-Tech suggested but use sections that are hidden or shown depending on the user selection.
There are three options:
two reports - like what MD-Tech is suggesting. two reports, on average, are more difficult to maintain.
one report/two sections - like what BUkHix suggests. you create the desired formatting in two separate sections, then use a parameter to hide/show the desired section
one report/two sub-reports - this gives you the most, finely-grained control over the formatting. the sub-reports display can also be controlled by a parameter.
In any case, you can control the image's X (distance from left margin) in v 11.0 using a conditional formula. In v 12.0, you can also control the Width property with a conditional formula. A conditional formula can reference a parameter field, so the positioning can make use of a user-supplied value.
You will also need to experiment with the image types, as Crystal Reports supports a limited set (JPG and BMP for sure).
Splitting this into 2 answers so much info incoming; firstly loading separate reports:
it is possible to select which reports are loaded at runtime by conditionally calling the Load() function of the document class. An example of this would be (in c++):
ReportDocument myDocument = gcnew myDocument();
if(wideIDcard)
{
myDocument->Load("wideIDCard.rpt");
}
else
{
myDocument->Load("narrowIDCard.rpt");
}
where the boolean wideIDCard is set from a dropdown box etc. from a front end. The ReportDocument myDocument can then be sent to the report viewer to view that report.
The quickest way to do this whould be to have 2 separate reports and then have the code Load() the correct one dependent on the user selection, which would come from a separate windows form. It is possible (though difficult) to create this form in such a way as to use it to set all the parameters for the report if you need it to be a single entry form.

Argument exception occurring on form.ShowDialog() when I change the sortorder of the form's data grid

Ok, I'm utterly confused by this situation, so bear with me.
In my application, if you click on a button I have an editor form open
dgEditor = new fmDataGridFieldEditor();
dgEditor.ShowDialog();
This works fine, and my form shows up and operates correctly. The form has a data grid in it with some specified fields. Now, if I then change data in one of the columns of the datagrid (a column that is just meant for numbers) and then change the sorting order by clicking on the column header, my form crashes. with an ArgumentException error that says "Object must be of type Int32" on the dgEditor.ShowDialog(); line.
I don't understand what is going on or even how to start debugging this. This doesn't happen when I modify existing rows, or if the rows I enter are already sorted (e.g. 0,1,2 is fine but 0,1, 0 causes the crash).
Furthermore, I have visual studio 2010 setup to break on all exceptions, not just unhandled ones, but I'm getting an exception in the same place.
Finally, I tied the data grid's ColumnSortModeChanged event to show a message box, but even when the sorts don't crash the form, the message box doesn't show.
I'm at a loss on how to proceed with this.
The debugger shows the last line of code that you wrote. Which is the ShowDialog() call. If you look at Debug + Windows + Call stack then you see the methods in the .NET framework that are involved. Scroll the window up if necessary to see them all. DataGridView has a lot of built-in functionality, the source code isn't readily available although you can get it from the Reference Source. Not that this will help much, there's rather a lot of it.
Clearly there's some invalid data in one or more rows. Looks like a leading space, only guessing here without sitting in front of your machine. Implement the CellValidating event so the user cannot enter an improperly formatted number.
I just had this happen to me in VB. What I discovered was that when I copied the values from a textbox into the grid I didn't do a cast to int. Being VB I assumed it would cast implicitly, but the cell value is, I guess, an object, so it happily took a string. Everything looked right and worked right, until I happened to sort on that column. Maybe this will help someone else.
ShowDialog will throw an error if you are trying to create a PictureBox dynamically on the TableLayoutPanel. It does not allow two PictureBox elements to add a similar index on the Table or you could have a error if your are using MemorySTream and not closing it properly.

Categories