17570

Bind .xml file to treelistiview in objectlistview

Question:

I have to bind xml to Treelistview in Objectlistview<br /><strong>TestSuite.xml</strong>

<TestSuite> <TestCase name="TestCase" UID="" State="" DataSourceId=""> <TestModule name="Recording" State="Checked" UID=""></TestModule> <TestModule name="Recording1" State="Checked" UID=""></TestModule> </TestCase> <TestCase name="TestCase" UID="" State="" DataSourceId=""> <TestModule name="Recording" State="Checked" UID=""></TestModule> <TestModule name="Recording1" State="Checked" UID=""></TestModule> </TestCase> </TestSuite>

<strong>TestSuite.cs</strong>

namespace ObjectListViewDemo { public class TestSuite { [XmlArrayAttribute("TestCase")] public TestModule[] TestModules; } public class TestCase { [XmlAttribute] public string name; [XmlAttribute] public string UID; [XmlAttribute] public string State; [XmlAttribute] public string DataSourceId; } public class TestModule { [XmlAttribute] public string name; [XmlAttribute] public string State; [XmlAttribute] public string UID; } }

Written below code on form load to bind xml to treeview

private void TestTreeViewForm_Load(object sender, EventArgs e) { StreamReader sr = new StreamReader(Path.Combine(@"D:\Test Suite", "TestSuite.xml")); XmlSerializer xmlSerializer = new XmlSerializer(typeof(TestSuite)); TestSuite testSuite = (TestSuite)xmlSerializer.Deserialize(sr); // Deserialize other XML as necessary List<TestSuite> TestSuiteCollection = new List<TestSuite>(); TestSuiteCollection.Add(testSuite); // Add other MyTrack objects to collection treeListView1.SetObjects(TestSuiteCollection); }

Added one column in treelistview

this.olvColumn1.AspectName = "Name"; this.olvColumn1.Text = "Name"; this.olvColumn1.Width = 180; this.olvColumn1.WordWrap = true; this.treeListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.olvColumn1});

After running in treelistview its showing error "'Name' is not a parameter-less method, property or field of type..."

I have refer below link for loading xml to treelistview

<a href="https://stackoverflow.com/questions/8855773/binding-xml-file-to-objectlistview" rel="nofollow">Reference link</a>

Answer1:

public MyForm() { InitializeComponent(); //LoadTree(); SetupColoumn(); LoadTree1(); } private void SetupColoumn() { // Get the size of the file system entity. // Folders and errors are represented as negative numbers this.olvColumn1.AspectGetter = delegate(object x) { return ((XmlNode)(x)).Attributes["name"].Value; }; } private void LoadTree1() { XmlDocument reader = new XmlDocument(); reader.Load(@"F:\Test1.xml"); ArrayList roots = new ArrayList(); String xpath = "/TestSuite/TestCase"; var nodes = reader.SelectNodes(xpath); foreach (XmlNode childrenNode in nodes) { roots.Add(childrenNode); //roots.Add(childrenNode.Attributes["Name"].Value); } this.treeListView1.CanExpandGetter = delegate(object x) { //return ((MyFileSystemInfo)x).IsDirectory; return ((XmlNode)x).HasChildNodes; }; this.treeListView1.ChildrenGetter = delegate(object x) { ArrayList children = new ArrayList(); var node1 = ((XmlNode)x).ChildNodes; if (x is XmlNode) { //foreach (XmlNode node in roots) { foreach (XmlNode n in node1) { children.Add(n); } } } return children; }; treeListView1.SetObjects(roots); }

}

Recommend

  • How to log test pass/fail results of JUnit4 to a file?
  • Maven is not using the proper Java compiler
  • How to write a NUnit test for an NUnit add-in?
  • Is test suite deprecated in PyUnit?
  • MySQL: limit query or subquery (in left/inner join?)
  • Serialize and DeSerialized derived classes from the base class
  • Deserialize XML in a WP8 Application
  • Img.onload not firing when dynamically setting src to dataURI
  • Should any domain object, not be serializable?
  • Get rid of root element when serializing array
  • Object xml deserialization issue?
  • Prevent XmlSerializer from auto instantiating List's on Deserialize
  • Xml serialization - collection attribute
  • How do I (de)serialize a serializable dictionary with string array values?
  • Saving application state AIR
  • Testing polymer 1.0 components with iron-ajax using wct
  • An unhandled exception of type 'System.AccessViolationException' occurred
  • How to export Selenium Test Suite/Case as C#
  • IsAuthenticated is false! weird behaviour + review question
  • how to deserialize jqgrid multiple group search criteria in asp .net mvc2
  • how to pass the result model object out of System.Web.Http.ModelBinding.IModelBinder. BindModel?
  • Data Type of Columns in a List - R
  • Eclipse: missing requirement E4 RCP patch when installing properties editor
  • Add log separators to all fixtures in unittests
  • Getting a generic method to infer the type parameter from the runtime type
  • How to write string.Contains(someText) in expression Tree
  • DependencyObject.AssociatedObject is always null
  • Avoid Inheriting Super Class Tests in ScalaTest
  • when does setTimeout start executing in a inline
  • How do I register classes by both interface and namespace with Windsor?
  • Xcode 4 NSLog Macro link in Xcode 3
  • Play WS (2.2.1): post/put large request
  • Python urlparse: small issue
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • Deserializing XML into class C#
  • JSON with duplicate key names losing information when parsed
  • Jquery - Jquery Wysiwyg return html as a string
  • Is there a mandatory requirement to switch app.yaml?
  • How to Embed XSL into XML