开发者

How do I adjust overall width of rdlc report when some columns are hidden?

开发者 https://www.devze.com 2022-12-22 19:31 出处:网络
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 ch

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, on开发者_如何学Cly an actual value is allowed.

Any suggestions?


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.


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.


@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);
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消