Report Design
 Crystal Reports Forum : Crystal Reports .NET 2003 : Report Design
Message Icon Topic: How to customize report columns at runtime? Post Reply Post New Topic
Author Message
kent82
Newbie
Newbie


Joined: 22 Nov 2006
Online Status: Offline
Posts: 2
Quote kent82 Replybullet Topic: How to customize report columns at runtime?
    Posted: 22 Nov 2006 at 6:58pm
Hi, Brian Bischof
 
I recently bought your book "Crystal Reports .NET Programming" and i researching on how print a dynamic columns report where user can  choose which column/field in the database table that they wish to see.
However, i couldnt find a solution on this, i hope you can help me.
 
I try several methods and one of them is to create a customized datatable where i populate certain specified columns. And then fill records from the database. This method could not work and the report is blank. If i drag and drop the database field from the Field Explorer then it would display the columns that i have dropped there.
 
Another method that i have tried is according to your book on Chapter 17 (Dynamic Data Source) where i create a dataset and i wrote a sql query to select 2 table fields out of 10 and fill it into the dataset. I set the datasource to my report and the report is also blank.
 
I hope you can help me on this topic as i have been googling for 2 weeks already :) . i appreciate if you can direct me which chapter of your book (Crystal Reports .NET Programming) can i look into to find a solution. Thanks
 
Regards
Kent
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 23 Nov 2006 at 12:23am
Hi Kent,

It sounds like the first problem is just getting the report to print some data. After that you can worry about the dynamic columns. If you are using the samples from my book, then please just do the samples exactly as they say without changing anything to make sure they are working. I often get questions from people who say that a sample doesn't work but then I find out that they skipped a step that they felt wasn't important (but it really was).

Once you get the sample to work, then you can do this by creating a report based off of a dataset and making the dataset dynamic. Custom build a select statement to choose the two fields you need to print but always assign the field names an alias. Here are two examples:

Select Country as Field1, State as Field2 From Customer

Then you can print Field1 and Field 2 and it shows the Country and State data. If the user chooses to print City and Zip Code instead, then your SQL string would be:

Select City as Field1, ZipCode as Field2 From Customer

This way, Crystal Reports is still printing Field1 and Field2 on the report and you won't get a blank report. The key is to use the Sql aliases to rename the dynamic fields to something generic so that the same fields are always being passed to the dataset. If you didn't use an alias then CR would be getting different field names everytime and the report wouldn't print any data.

But remember, get my sample to work from the book with NO CHANGES first before adding any complexity.

Hope this helps.
IP IP Logged
kent82
Newbie
Newbie


Joined: 22 Nov 2006
Online Status: Offline
Posts: 2
Quote kent82 Replybullet Posted: 27 Nov 2006 at 10:50pm
Hi BrianBischof,
 
Thanks for the reply. After tinkering around with the codes in your book, and the pointers you gave me. I manage to create a customized dataset schema and bind it to my report. I use the sql query to select columns as alias. However, there is a problem in my current solution
 
Let say my query is Select Country as Field1, State as Field2 From Customer
 
Field1          Field2
England      State1
U.States     State2
 
then i change my query to Select City as Field1, ZipCode as Field2 From Customer
 
Field1         Field2
London       99999
Seattle       22222
 
How can i change the name of the header(Field1/Field2) to match the description of my columns. I need the header text columns to change dynamically to match my column data as well.
 
For eg.
 
Country      State
England      State1
U.States     State2
 
City            ZipCode
London       99999
Seattle       22222
 
Another question is , is there anyway that i can hide the columns in the report for eg. client at first wants to view only country and state. Then he/she add addtional column which is city to the initial country and state columns. Now we have 3 columns. Do i need to drag and drop all the possible columns on the report design layout? then hide and view  the columns according to user's input?
 
Best Regards


Edited by kent82 - 27 Nov 2006 at 10:51pm
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 28 Nov 2006 at 1:11am
Hey Kent, glad you made progress.

Re your questions, to change the Header fields you have to do that using the object model and change it in your code prior to previewing the report. I have an example of how to do this somewhere in the second half of the book. Another option is to change the Headers to be formulas and change each formula in the program. This is pretty simple to change formula values in code.

Re the second question, yes you need to put all three columns onto the report in design mode. Then hide the one(s) that you don't put any data into. Again, how to hide report objects in in the second half of the book.

HTH,

Brian

IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.047 seconds.