当某些列隐藏时,如何调整 rdlc 报告的整体宽度?

发布于 2024-08-23 22:34:55 字数 285 浏览 4 评论 0原文

我有一个可自定义的 rdlc 报告,用户可以在其中选择要显示的列。所有列都包含在报表设计器中,我使用参数根据用户的选择隐藏/显示列。报表正确呈现,并且仅显示选定的列,但是,报表的整体宽度相同,就好像所有列都可见一样。这意味着报表可以在所选列的右侧有一个巨大的空白区域,这看起来很愚蠢。

所以我的问题是:有没有办法在运行时动态调整报告宽度以避免报告中出现大而愚蠢的空白区域?我尝试在设计器中通过为报表主体的宽度分配一个参数来做到这一点......但这是不允许的。宽度不能是设计器中任何类型的表达,只允许实际值。

有什么建议吗?

I have a customizable rdlc report where the user can choose which columns to show. All the columns are included in the report designer, and I use parameters to hide/show columns based on the user's choice. The report renders correctly, and only shows the selected columns, HOWEVER, the overall width of the report is the same as if all the columns were visible. This means that the report can have a huge empty area to the right of the selected columns, which looks very silly.

So my question: Is there a way to adjust the report width dynamically at runtime to avoid a large silly empty area in the report? I attempted to do this in the designer by assigning a parameter to the width of the report body....but that was not allowed. The width cannot be an expression of any kind in the designer, only an actual value is allowed.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

吃不饱 2024-08-30 22:34:55

我有一个可能很愚蠢的解决方法,但至少对我有用;
因此,在完成 rdlc 报告设计器后,将其关闭,然后使用 xml 编辑器打开 rdlc 报告,然后在 后面的 标记内打开。 ... 标签中可以看到一个 ... 标签,其中包含报表的宽度,将其值修改为非常小的值(假设1in),这应该使报告显示没有愚蠢的空格。

但请记住,如果您在设计器中打开 rdlc 报告,它将重置视图区域的宽度,因此问题将再次出现,因此请在完成报告后执行此操作。

我知道这是一个愚蠢的解决方案,但在开发人员方面比在客户方面更愚蠢^_^。

希望这有帮助。

I have a workaround that might be silly, but at least it works for me;
so after you're finished with the rdlc report designer, close it and then open the rdlc report with the xml editor, then within the <Report> tag right after the <body>...</body> tag you can see a <width>...</width> tag that contains the width of the report, modify its value to a really small value ( lets say <width>1in</width>), this should make the report show without the silly spaces.

But remember that if you open the rdlc report in the designer, it will reset the width to the view area so the problem will appear again, so do it after you are done from the report.

I know its a silly solution, but its better silly at the developer side than at the customer side ^_^.

Hope this helps.

怎樣才叫好 2024-08-30 22:34:55

如果可能的话,您可以增加另一列的宽度以填充空白空间。
我按如下方式解决了这个问题。

例如,我有“名称”和“折扣”列。折扣可以隐藏,我应该将Name.Width更改为Name.Width+Discount.Width。

我在“Name”列中创建了一个新列(将其称为“NameExt”),其宽度与 Discount.Width 相同。合并“Name”列和“NameExt”列的单元格。然后为“Discount”设置可见性规则,为“NameExt”设置反向可见性规则。

希望这能有所帮助。

If it possible you can increase width of another column to fill empty space.
I solved this problem as follows.

For example I have columns 'Name' and 'Discount'. Discount can be hidden and I should change Name.Width to Name.Width+Discount.Width.

I've made a new column (call it 'NameExt') right from 'Name' column with the same width as Discount.Width. Merged cells of 'Name' column and 'NameExt' column. Then set visibility rule for 'Discount' and inverse visibility rule for 'NameExt'.

Hope this can help.

塔塔猫 2024-08-30 22:34:55

@SayedAbolfazlFatemi,你真的用这个来测试我的记忆力,因为我的评论是 8 年前的,但我会试一试!

使用 XML 编辑器而不是设计器打开 RDLC 文件,您将看到每列都给出了以英寸为单位的尺寸 (0.3in<宽度>13.7191cm)。我用来在运行时更改大小的方法是使用 ReportViewer 上的 LocalReport.LoadReportDefinition 操作和加载 XML。像这样的东西;

DataTable dt = new DataTable();
da.Fill(dt);  

string reportPath= HttpContext.Current.Server.MapPath("~/ReportName.rdlc");
XmlDocument doc = new XmlDocument();
doc.Load(reportPath);
XmlNodeList sizeList = doc.GetElementsByTagName("Size");
XmlNodeList widthList = doc.GetElementsByTagName("Width");

// Obviously you'll want to throw in some of your column conditions to hide
foreach (XmlNode node in sizeList)
    node.InnerText = "0.0000in";

foreach (XmlNode node in widthList)
    node.InnerText = "0.0000in";

ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
Microsoft.Reporting.WebForms.ReportDataSource source = new Microsoft.Reporting.WebForms.ReportDataSource("DataSourceName", dt);
using (var textReader = new System.IO.StringReader(doc.OuterXml))
{
    ReportViewer1.LocalReport.LoadReportDefinition(textReader);
}

@SayedAbolfazlFatemi, you're really testing my memory with this one as my comment was 8 years old but I'll give it a shot!

Open up the RDLC file with an XML editor instead of the designer and you'll see each column is given a size in inches (<Size>0.3in</Size> or <Width>13.7191cm</Width>). The method I used to change the size at runtime was to manipulate and load the XML with LocalReport.LoadReportDefinition on the ReportViewer. Something like this;

DataTable dt = new DataTable();
da.Fill(dt);  

string reportPath= HttpContext.Current.Server.MapPath("~/ReportName.rdlc");
XmlDocument doc = new XmlDocument();
doc.Load(reportPath);
XmlNodeList sizeList = doc.GetElementsByTagName("Size");
XmlNodeList widthList = doc.GetElementsByTagName("Width");

// Obviously you'll want to throw in some of your column conditions to hide
foreach (XmlNode node in sizeList)
    node.InnerText = "0.0000in";

foreach (XmlNode node in widthList)
    node.InnerText = "0.0000in";

ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
Microsoft.Reporting.WebForms.ReportDataSource source = new Microsoft.Reporting.WebForms.ReportDataSource("DataSourceName", dt);
using (var textReader = new System.IO.StringReader(doc.OuterXml))
{
    ReportViewer1.LocalReport.LoadReportDefinition(textReader);
}
平安喜乐 2024-08-30 22:34:55

报表的实际宽度在设计器中是固定的,因此报表本身无法在运行时调整大小。您是对的,在报表设计器中无法分配表达式或动态分配宽度值到报表、页面或正文。

但是,rdlc 报告的 CONTAINER 宽度可以在运行时控制。如果将报表查看器放入面板控件中,您应该能够实现所需的输出。由于您的 UI 允许用户决定要包含哪些列,因此您应该能够为每个可选列附加一个宽度值,并对这些值求和,并根据需要调整容器的大小。

请记住,如果您重新调整容器的大小,报表中的空白问题就会变成表单上的空白问题。报告周围仍然有一个紧密的框架,框架外有空白区域,这很可能就是您想要的。

HTH&干杯,

CEC

The actual width of the report is fixed in the designer so the report itself can not be resized at run time. You are correct that in the report designer there is no way to assign an expression or to dynamically assign a width value to the report, page or body.

However, the width of the CONTAINER for the rdlc report can be controlled at run time. If you put your report viewer inside a panel control you should be able to achieve the desired output. Since your UI allows the users to decide which columns to include you should be able to attach a width value to each optional column and sum those and resize the container as appropriate.

Do remember that if you re-size the container a white space issue inside the report simple turns into a white space issue on the form. Still a tight frame around the report with empty space outside of that frame may well be what you want.

HTH & Cheers,

CEC

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文