隐藏reportitem
1.报表中添加参数, Boolean TblInvoice
2.程序添加参数
Microsoft.Reporting.WinForms.ReportParameter[] parameters = new Microsoft.Reporting.WinForms.ReportParameter[1];
parameters[0] = new Microsoft.Reporting.WinForms.ReportParameter("TblInvoice", Boolean.TrueString);
3设计报表
选中要控制是否显示的控件,鼠标右键=>属性=>Visibility=>Initial Visibility=>选择Expression=>=CBool(Parameters!TblInvoice.Value)
即可!
注意:表达式的写法CBool(Parameters!TblInvoice.Value),必须使用CBool转换否则可能不正确!
GetDefaultPageSettings
这是LocalReport的方法,可是他获得却不是rdlc里面的pageWidthpageheight设置,感觉没啥大用。
使用下面的方法读取RDLC里面的PageWidth等等属性
代码如下:
/// <summary>
/// 从RDLC文件读取文件
/// </summary>
public bool ReadPageSettingsFromRDLC()
{
if (string.IsNullOrEmpty(this.m_localReport.ReportPath))
{
return false;
}
StringBuilder sbzzm = new StringBuilder();
sbzzm.Append("<DeviceInfo> <OutputFormat>EMF</OutputFormat> ");
XmlReader xmlReader = XmlReader.Create(this.m_localReport.ReportPath);
ReadElementString(xmlReader, "PageWidth", "8.5in", "PageWidth", sbzzm);
ReadElementString(xmlReader, "PageHeight", "11in", "PageHeight", sbzzm);
ReadElementString(xmlReader, "TopMargin", "0cm", "MarginTop", sbzzm);
ReadElementString(xmlReader, "LeftMargin", "0cm", "MarginLeft", sbzzm);
ReadElementString(xmlReader, "RightMargin", "0cm", "MarginRight", sbzzm);
ReadElementString(xmlReader, "BottomMargin", "0cm", "MarginBottom", sbzzm);
sbzzm.Append("</DeviceInfo>");
m_szDeviceInfo = sbzzm.ToString();
xmlReader.Close();
return true;
}
private void ReadElementString(XmlReader xmlReader, string elementname, string defstring, string nodename, StringBuilder sbzzm)
{
string tempString;
sbzzm.Append(" <");
sbzzm.Append(nodename);
sbzzm.Append(">");
if (xmlReader.ReadToFollowing(elementname))
{
tempString = xmlReader.ReadElementString(elementname);
if (string.IsNullOrEmpty(tempString))
{
sbzzm.Append(defstring);
}
else
{
sbzzm.Append(tempString);
}
}
else
{
sbzzm.Append(defstring);
}
sbzzm.Append("</");
sbzzm.Append(nodename);
sbzzm.Append(">");
}