New to Telerik UI for WinForms? Download free 30-day trial

Binding to XML Data

RadTreeView can consume XML data both by directly loading it (see Serialize/Deserialize to XML) or by loading it to a DataSet for binding. The following example uses a sample "Table of contents" XML. Each node element in the table of contents has a "Title" element, "id" and "parentid".

        <Title>Main Title</Title>
        <Title>Child Title</Title>

Assuming that "toc.xml" is in the TreeView\DataBinding directory which is relative to the directory of the the executable, the following code can be run from the form Load event handler. A new DataSet object is created and the DataSet. ReadXml() method consumes the sample data. The element being shown is the DisplayMember property "Title". The ValueMember property is set to the "id" element and it will be available in the Value property of each RadTreeNode at runtime. The ParentMember and ChildMember properties define the relation between the records in the data source object:

WinForms RadTreeView Binding to XML Data

DataSet tocDataSet = new DataSet("Toc");
this.radTreeView1.DataMember = "Node";
this.radTreeView1.DisplayMember = "Title";
this.radTreeView1.ChildMember = "id";
this.radTreeView1.ParentMember = "parentId";
this.radTreeView1.DataSource = tocDataSet;

Dim tocDataSet As DataSet = New DataSet("Toc")
Me.RadTreeView1.DataMember = "Node"
Me.RadTreeView1.DisplayMember = "Title"
Me.RadTreeView1.ChildMember = "id"
Me.RadTreeView1.ParentMember = "parentId"
Me.RadTreeView1.DataSource = tocDataSet

See Also

In this article