Print Page | Close Window

remove columns from report via code at runtime

Printed From: Crystal Reports Book
Category: Crystal Reports .NET 2003
Forum Name: Writing Code
Forum Discription: .NET 2003 programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=171
Printed Date: 02 May 2024 at 2:24am


Topic: remove columns from report via code at runtime
Posted By: thebasicimage
Subject: remove columns from report via code at runtime
Date Posted: 28 Jan 2007 at 9:57am
I have a very simple report which contains all the columns from one of my database tables and some columns that are the result of Crystal code.
 
What i need to do is add/remove the columns from the report during runtime (depending upon which column(s) the user has selected to view)
 
Thank you



Replies:
Posted By: BrianBischof
Date Posted: 28 Jan 2007 at 12:42pm
Unfortunately, you can't remove the columns. Instead you have to hide the ones you don't want to see. The problem with this is that it leaves gaps in your report. What some people do is create a dataset object with generic column names (Col1, Col2, etc.) and build a report using these generic column names. Then they use a dynamic SQL query which uses aliases to put the data into the generic column names. That way, each adjacent column has data in it (since you create the query on the fly), and you just turn off the unused columns at the end of the report. This prevents having gaps in the report.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: thebasicimage
Date Posted: 28 Jan 2007 at 6:34pm
Thank you very much for you quick reply.  I had seen your response to http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=21 - http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=21  and so was wondering about the "hide" functionality. 
 
Thank you for pointing out that the columns only become invisible and do not change the column spacing.  This is critical for my need because I will be reporting on 50 columns and they can choose to view only 1 or all... So it sounds like "hide" by itself will not do what I need.
 
two things which might slightly complicate your proposed solution are:
(1) some of my columns were going to be formula fields (to decode some database fields)
(2) my columns are of different data types (datetime,string,int)
 
The 2nd one doesn't seem like that big of a problem, but the first one may require me to use a different strategy?  I would really appreciate your input on this.
 
Thank you.



Print Page | Close Window