0

I am using the System.Windows.Forms.WebBrowser to display XML. If i load the XML into the Control by default the elements are completely expanded. The user can collapse them manually to the depth/level that he wants.

Is it possible to collapse the elements to a certain depth/level with C# code. Let's say the XML elements are expanded to a depth of 2 or 3 and all the below elements are collapsed?

The thread that I tried is the below one, but it did not solve my problem completely.

collapse all elements for loaded xml in webbrowser control using c#

Community
  • 1
  • 1
NETdev
  • 1
  • 1

1 Answers1

0

You can definitely do that if you check how the generated structure looks - the the depth of the collapse <a> tag acts as the indicator of how deep in the tree you are. So you can just use JavaScript to match a certain level of links and collapse them. You can do that either manually (traversing the document and recursively entering the sub-elements while keeping a variable that will track the current depth - for the basics check this article ) or via some CSS-style element matching.

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • 1
    thanks for the response and the article link you ve placed. Good to know that the depth can be measured. I will study the XML javascript basics to build the right statement. – NETdev Mar 01 '15 at 15:47