When programming reprotviewer, I want to make a function that allows users to change the display/print columns, you only need to change the
1: // create a <visibility> node
2: XmlElement xev = this.xdc.CreateElement("Visibility");
3: // create a
4: XmlElement xeh = this.xdc.CreateElement("Hidden");
5: // set to display
6: xeh.InnerText = "false";
Then, use the appendchild method to add xeh to Xev, and then add the Xev node to the corresponding <tablecolumn> node.
However, you cannot hide or display columns after adding them. View the code. After each edit and change, the value of
However, it was later found that, if a column is hidden through vs, the value of
Differences between the two methods
- Design results in:
1: <Visibility>
2: <Hidden>true</Hidden>
3: </Visibility>
- Manually added results:
1: <Visibility xmlns="">
2: <Hidden>true</Hidden>
3: </Visibility>
It is found that the namespace of the manually added <visibility> node is xmlns = "". the initial idea is to remove this empty namespace, on the internet found that many people encounter this problem, but are not resolved until you see this article [http://blog.tianya.cn/blogger/post_show.asp? Blogid = 2524806 & postid = 21711977 & idwriter = 7649736 & Key = 746436846 # bottom]
Then I suddenly realized that.
1: /*
2: When we appendchild, if the parentnode has the xmlns attribute and the newly added node does not specify xmlns or is null during creation, the sub-node will have the xmlns = "" attribute and cannot be removed.
3:
4: cause: when the parent node has the xmlns attribute, the child node must specify the xmlns attribute. However, when the xmlns attribute of the child node is the same as the namespace of the parent node, the sub-node does not display the xmlns attribute.
5:
6: the root cause of the above problem is an error we understand. We believe that this attribute should not appear if no namespace is specified for the subnode. The opposite is true, this attribute does not appear when we specify the same namespace as the parent node for it.
7: */
Since I used xmldocument to operate the rdlc file, I defined the namespace
1: // Add a namespace to search nodes using the XPath path
2: AddNamespace("C", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");
3: AddNamespace("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");
Therefore, when creating <visibility>, you must inherit the xmldocument namespace.
1: // create a <visibility> node
2: XmlElement xev = this.xdc.CreateElement("Visibility",this.xdc.DocumentElement.NamespaceURI);
3: // create a
4: XmlElement xeh = this.xdc.CreateElement("Hidden",this.xdc.DocumentElement.NamespaceURI);
5: // set to display
6: xeh.InnerText = "false";
In this way, the modified rdlc file is consistent with the result designed by the Vs report editor, and the column display and hiding can be well implemented.
Summary: I have never been familiar with XML programming, and I am very familiar with the basic knowledge and attributes of namespaces.