Writing Code
 Crystal Reports Forum : Crystal Reports .NET 2003 : Writing Code
Message Icon Topic: remove columns from report via code at runtime Post Reply Post New Topic
Author Message
thebasicimage
Newbie
Newbie
Avatar

Joined: 28 Jan 2007
Online Status: Offline
Posts: 2
Quote thebasicimage Replybullet Topic: remove columns from report via code at runtime
    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
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
IP IP Logged
thebasicimage
Newbie
Newbie
Avatar

Joined: 28 Jan 2007
Online Status: Offline
Posts: 2
Quote thebasicimage Replybullet 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 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.
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.016 seconds.