[英]Crystal Report Making on the basis of Number of Selected Attributes from check list, how can we do so?
I am developing application in C# Windows Forms, i make crystal reports on the basis of data collection list in c#, for example i have a table having EmpID, Name, Sponsor, Job Title, Nationality etc. I bring them in collection in c# and pass it to crystal report, where i see my attributes in Database fields, if i drag and drop those fields on the report, for example Name, Job Title, Nationality, then i can see their columns coming in Details section, but the issue is, i have about 25 attributes and i have made a check list of 25 attributes in c#, if i check 13 attributes, it should make a report of 13 columns, the problem is, we make report in crystal report on the basis of drag and dropping fields, how can i dynamically do this, means if there are 13 fields selected in c# check list, there should be just 13 columns in report. 我正在C#Windows窗体中开发应用程序,我基于c#中的数据收集列表制作水晶报表,例如,我有一个包含EmpID,名称,赞助者,职务,国籍等的表。我将它们带入c#中,将其传递给Crystal报表,我可以在“数据库”字段中看到我的属性,如果我将这些字段拖放到报表上,例如“姓名”,“职务”,“国籍”,那么我可以在“详细信息”部分看到它们的列,但是问题是,我大约有25个属性,并且我在c#中制作了一个25个属性的检查清单,如果我检查了13个属性,它应该制作一个13列的报表,问题是,我们在拖动和修改的基础上在Crystal报表中制作了报表删除字段,我该如何动态地做到这一点,意味着如果在c#检查列表中选择了13个字段,则报告中应该只有13列。 Please find the image attached, "How currently i am doing" Please zoom it by right click on it, and open in new window.
请找到附件中的图像“我目前的状况”,请右键单击以放大它,然后在新窗口中打开。
I think that the easiest way to approach this, considering data type representations and all of the Crystal complexity under the covers, is to layout your report with all 25 fields sized appropriately. 我认为,考虑到数据类型表示和所有Crystal复杂性,解决此问题的最简单方法是使用所有25个字段的适当大小来布局报表。
Then, at runtime, you will need to reposition the report objects, which could be a little tricky due to the relatively unstructured way in which crystal provides the information. 然后,在运行时,您将需要重新定位报表对象,由于Crystal提供信息的方式相对非结构化,因此这可能会有些棘手。
The way I would approach this is to loop through the report objects and generate one SortedList for the data fields and one SortedList for the header fields. 我将采用的方法是遍历报表对象并为数据字段生成一个SortedList,为标题字段生成一个SortedList。 They should be sorted on their Left position so that you can process them in appearance order.
它们应该在其“左”位置排序,以便您可以按外观顺序对其进行处理。
Once you have the sorted lists of objects, you can cycle through each one and, if it was not selected by the user, set the Width to 0. 找到对象的排序列表后,可以循环浏览每个对象,如果用户未选择,则将“宽度”设置为0。
As you are moving through the fields, you will keep track of the current left position. 在字段中移动时,将跟踪当前的左侧位置。 The first field that you process will set your starting point, even if it is not visible.
您处理的第一个字段将设置您的起点,即使它不可见。 Then, for all subsequent fields, if the field is visible, you will set its left value to the current left position, then add its width plus some separator space to the current left position for the next field.
然后,对于所有后续字段,如果该字段可见,则将其左侧值设置为当前左侧位置,然后为下一个字段将其宽度加上一些分隔符添加到当前左侧位置。
Hopefully this will help you solve your problem. 希望这可以帮助您解决问题。
Give a look at these links 看看这些链接
Using this Google Search 使用此Google搜索
It sounds like this would be a good place for a cross-tab report. 听起来这将是交叉表报告的好地方。 In this case you'd need to add a cross tab to your report header or footer and pass your data into the report with a column for each attribute descriptions and then group on the attribute description.
在这种情况下,您需要在报表的页眉或页脚中添加一个交叉表,并将数据传递到报表中,并为每个属性描述添加一列,然后对属性描述进行分组。 See below for details:
详情请见下文:
Data:
RowID ColDesc ColValue
1 Attr1 Value1
1 Attr2 Value2
2 Attr1 Value3
Then you can add your crosstab where your row field is RowID, your column field is ColDesc and the field to summarize is ColValue. 然后,您可以添加交叉表,其中行字段为RowID,列字段为ColDesc,要汇总的字段为ColValue。 You can use a Max of summary on the summarized field since it is different.
您可以在摘要字段中使用摘要总数的最大值,因为它有所不同。
This is untested, but I believe that the output for this should be: 这未经测试,但我认为其输出应为:
CrossTab:
Attr1 Attr2
1 Value1 Value2
2 Value3
As you can see that as you add a new attribute it will show up as a new column in the crosstab. 如您所见,添加新属性后,它将在交叉表中显示为新列。 As I said previously, this is untested so I apologize for any errors, but I hope it is enough to help you out.
就像我之前说的那样,这是未经测试的,因此对于任何错误我深表歉意,但我希望这足以帮助您。 Thanks
谢谢
Crystal Reports will not automatically add columns & headers to a report given a list of fields. 给定字段列表,Crystal Reports不会自动将列和标题添加到报表中。
My recommendation is to use the Report Application Server .NET SDK to dynamically alter a report. 我的建议是使用报表应用程序服务器.NET SDK动态更改报表。 The link includes the API reference, as well as samples.
该链接包括API参考以及示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.