C# - Crystal Reports simple question

EFileTahi-A

Well-known member
Joined
Aug 8, 2004
Messages
539
Location
Portugal / Barreiro
How do I access the existing fields on a CrystalReport Designer?

I mean, imagine that I create a TEST named text field in CrystalReport1.rpt and I would like to access it like:
Code:
CrystalReport1 myReport = new CrystalReport1();
myReport.? //now what?

Tks in advance!
 
To Access it
Code:
TextObject textObject;
textObject = myReport.ReportDefinition.ReportObjects["TEST"] as TextObject;

Then say to change the text
Code:
textObject.Text = "Some Text";
 
pendragon said:
To Access it
Code:
TextObject textObject;
textObject = myReport.ReportDefinition.ReportObjects["TEST"] as TextObject;

Thank you very much for the reply, however, I have some doubts:

1 - -Is "TextObject" = "System.Windows.Forms.TextBox"? Or I need some special namespace setting?

2 - my myReport.ReportDefinition. does not lists the "ReportObjects"...

Sorry, kind noob in both C# and Crystal Reports... but expecially Crystal...
 
Ok, nevermind the last one, I missed the Correct Crystal namespace...

Anyway, it give me an error when executing this line of code:
Code:
txtbox = myReport.ReportDefinition.ReportObjects["test"] as TextObject;
Error Menssage:
An unhandled exception of type CrystalDecisions.CrystalReports.Engine.InternalException occurred in crystaldecisions.crystalreports.engine.dll

Additional information: "Unable to find the report in the manifest resources. Please build the project, and try again.

My Code:
Code:
TextObject txtbox;
CrystalReport1 myReport = new CrystalReport1();
txtbox = myReport.ReportDefinition.ReportObjects["test"] as TextObject;
txtbox.Text = "BLA";
Form1 form1 = new Form1();
form1.crystalReportViewer1.ReportSource = myReport;
form1.ShowDialog();

...
 
Never had that error so not sure what it is.

I always put the code in the report viewers load event

eg :

PHP:
private void CrystalReportViewer1_Load(object sender, System.EventArgs e)
{
	crReportDocument = new OpenItem();

	TextObject textObject;
	textObject = crReportDocument.ReportDefinition.ReportObjects["txtRepDate"] as TextObject;
	textObject.Text = "For Month Ending " + RepDate.ToString();

	CrystalReportViewer1.ReportSource = crReportDocument;
}

Have never tried to do this from another program so not sure if you need to do anything else but if you do the above I think it will work

Just to let you know these are the two namespaces I add to the program

PHP:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
 
Last edited by a moderator:
Damn, I just cant do it! It keeps giving me the same error, and the worst thing, I cant find any good newbie tutorial on the web, the ones I found either r too basic (only teach you how to link a report to an DataBase), or just too complex (for experts users only).

PS: If Crystal Reports is so Great (so I heard), why cant find any decent tutorial (.NET)? I mean, I dont need a good tutorial, a decent (avarage) tutorial would be enought... as long it covers "changing" / "creating" a report during runtime...

Pendragon, could you be kind enought to attach a fully working example from the code you post? (beginning to desperate, cooze I need this working until friday :(, or my boss will kill me)
 
Last edited by a moderator:
Ahh, thanks once more Pendragon, but, I managed to fix the error message before ur post :). Yet, I have now only one last question:

- What if I want to code a CR to use a table.column in the report document? In other words, linking a specific field of the CR to a access database field, but during runtime..

Tks alot pendragon!
 
EFileTahi-A

Sorry but I am not quite sure what you are trying to do, if you mean can you link a text object to a database field and have the contents change for each record then I dont think this can be done (Never tried so could be wrong), you can use fomulas to show different fields for each record.

Could you give me a little bit more info please and I will try to help.
 
Last edited by a moderator:
Sorry I think I am being a little dense today and cant seem to picture what it is you are doing.

You have your data source defined in your report, are you wanting to change the grouping (which I am not sure can be done) or are you going to show one field or another depending on a criteria.

Unfortunately I am about to go home and my Internet access is not working at the moment :(
 
Well, I think Am the one whos not being clear enough lol.

Do u use messenger? If so, could I add you? That way, things would be much simple :)

Until tomorrow and thanks once more for the replies!
 
It would be easier but they dont let us use messenger here :(

If you can give me details of the report and what it is you need to do I will try to help.

I will try to check the forum as much as possible.
 
Hi penDragon, thanks for not giving up on me :)

Well, when you create a report, using crystal report wizard, you can choose a Database, tables and fields. When u run the applicantion in order to execute the report, the fields will show all available records within the targets table right?, So my point is, what if I want to change these fields in during runtime?

Imagine you have a report with the following config:

- OLEDB JetEngine driver 4.0 Linked to an Access Database named: "Games"
- You choose the "Strategy" table.
- The Available fields are:
- "name"
- "type"
- "Dificulty"
- "SystemReq"

- And then you choose the fields: "name" and "type";

The all point is:

- "What if I want to add another field to the report? like "Dificulty"? Or What - If I want to remove the fields existing fields ("name", "type") and add new ones? (all this during runtime, (by code))

I would also love to know how can I do this directly in the report designer, I mean changing the linked fields to the report? Havent figured it out yet. Am using crystal reports just for 3 days ago. Never used it before.

Thanks for you possible help pendragon
Best regards EFileTahi-A
 
Hi EFileTahi-A

Pennys dropped and I see what you are trying to do.

- "What if I want to add another field to the report? like "Dificulty"? Or What - If I want to remove the fields existing fields ("name", "type") and add new ones? (all this during runtime, (by code))

I dont believe you can do this with the version that comes with VS, I wanted to be able to create a report from a users selection and could not find any information to do it in .NET but did find a small article somewhere that said you had to buy the full version of CR.

You might find more info on this at http://support.businessobjects.com/, I must admit I gave up trying to do this in the end

I would also love to know how can I do this directly in the report designer, I mean changing the linked fields to the report? Havent figured it out yet. Am using crystal reports just for 3 days ago. Never used it before.

As far as doing it in the report, in the Field Explorer there is a section called Database fields, expand that and you will get a list of the tables in your report, expand the table to get the fields then just drag and drop the field you want.

To delete, select it and press delete

Hope this helps
 
Glad I could Help :D

Just got a new computer at Home XP Pro, Never used Messenger before, but this was something I was going to look into once my broadband had been set-up, as soon as I do I will let u know (probably a couple of weeks as I am waiting for parts).
 
pendragon said:
Glad I could Help :D

Just got a new computer at Home XP Pro, Never used Messenger before, but this was something I was going to look into once my broadband had been set-up, as soon as I do I will let u know (probably a couple of weeks as I am waiting for parts).

Ok, dontt forget to add me once ur connect to messenger :)! "efiletahi@hotmail.com"
 
Back
Top