EFileTahi-A Posted January 11, 2005 Posted January 11, 2005 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: CrystalReport1 myReport = new CrystalReport1(); myReport.? //now what? Tks in advance! Quote
pendragon Posted January 11, 2005 Posted January 11, 2005 To Access it TextObject textObject; textObject = myReport.ReportDefinition.ReportObjects["TEST"] as TextObject; [/Code] Then say to change the text [Code] textObject.Text = "Some Text"; [/Code] Quote
EFileTahi-A Posted January 11, 2005 Author Posted January 11, 2005 To Access it TextObject textObject; textObject = myReport.ReportDefinition.ReportObjects["TEST"] as TextObject; [/Code] 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... Quote
EFileTahi-A Posted January 11, 2005 Author Posted January 11, 2005 Ok, nevermind the last one, I missed the Correct Crystal namespace... Anyway, it give me an error when executing this line of 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: 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(); ... Quote
pendragon Posted January 11, 2005 Posted January 11, 2005 (edited) Never had that error so not sure what it is. I always put the code in the report viewers load event eg : 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 using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; Edited January 11, 2005 by pendragon Quote
EFileTahi-A Posted January 12, 2005 Author Posted January 12, 2005 (edited) Damn, I just can't do it! It keeps giving me the same error, and the worst thing, I can't 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 can't find any decent tutorial (.NET)? I mean, I don't 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) Edited January 12, 2005 by EFileTahi-A Quote
pendragon Posted January 12, 2005 Posted January 12, 2005 EFileTahi-A This is a really basic program but should give an idea of what to do. Hope it helps.TestPrint.zip Quote
EFileTahi-A Posted January 12, 2005 Author Posted January 12, 2005 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! Quote
pendragon Posted January 12, 2005 Posted January 12, 2005 (edited) 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 don't 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. Edited January 12, 2005 by pendragon Quote
EFileTahi-A Posted January 12, 2005 Author Posted January 12, 2005 Well, I mean a FieldText (group I guess)... Quote
pendragon Posted January 12, 2005 Posted January 12, 2005 Sorry I think I am being a little dense today and can't 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 :( Quote
EFileTahi-A Posted January 12, 2005 Author Posted January 12, 2005 Well, I think Am the one who's 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! Quote
pendragon Posted January 13, 2005 Posted January 13, 2005 It would be easier but they don't 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. Quote
EFileTahi-A Posted January 13, 2005 Author Posted January 13, 2005 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? Haven't 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 Quote
pendragon Posted January 13, 2005 Posted January 13, 2005 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)) [/Quote] I don't 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? Haven't figured it out yet. Am using crystal reports just for 3 days ago. Never used it before. [/Quote] 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 Quote
EFileTahi-A Posted January 13, 2005 Author Posted January 13, 2005 Thks for the post! But, tell me, where is the field explorer located? :D kinda blind out here... Quote
pendragon Posted January 13, 2005 Posted January 13, 2005 I had trouble finding it. :) Its View/Other Windows/Document Outline Quote
EFileTahi-A Posted January 13, 2005 Author Posted January 13, 2005 Hey! Great stuff! Thanks once more, yet, I would like to add u to my messenger buddy list (even if we can only chat at home). What do u say? Quote
pendragon Posted January 13, 2005 Posted January 13, 2005 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). Quote
EFileTahi-A Posted January 13, 2005 Author Posted January 13, 2005 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, dont't forget to add me once ur connect to messenger :)! "efiletahi@hotmail.com" Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.