Adding an object as a node to TreeView

  • Thread starter Thread starter Paul McKenna
  • Start date Start date
P

Paul McKenna

Hello

I have a treeview control on my form. The nodes of this tree are populated
with values from an XML file. Is there a way by which I could bind objects
to the tree instead of simple strings? This would make it easier for me to
refer data referenced by each node instead of having to re-read the XML file
each time.

Thank You
 
* "Paul McKenna said:
I have a treeview control on my form. The nodes of this tree are populated
with values from an XML file. Is there a way by which I could bind objects
to the tree instead of simple strings? This would make it easier for me to
refer data referenced by each node instead of having to re-read the XML file

Have a look at the 'TreeNode''s 'Tag' property.
 
Thank you very much. Exactly what I was looking for.

I have another question and this one is perplexing me!

As mentioned earlier, I am reading data from an XML into a dataset and then
transforming this dataset into the Tree. Something strange happends when I
read data from the XML into the dataset. I would assume that the column
names in the dataset would simply be the same as the tag names in the XML
but instead they are appended with "_Text".

Here is the code:
Dim io_XMLStream As New FileStream(str_Path, IO.FileMode.Open)

Dim xml_XMLReader As New XmlTextReader(io_XMLStream)

ds_XML.ReadXml(xml_XMLReader)

And the column names are populated as "c1_Text". The "_Text" part is
confusing me.. where did it come from? Is there anyway to avoid that?

Thanks in advance
 
Hi Paul,

You took this probably from the documentation.
Dim io_XMLStream As New FileStream(str_Path, IO.FileMode.Open)
Dim xml_XMLReader As New XmlTextReader(io_XMLStream)
ds_XML.ReadXml(xml_XMLReader)

You can delete the two first rows and just do
ds_XML.ReadXML(strpath)

Your columnnames are
Ds.tables(0).datacolumn(0).columnname.tostring 'first columnname

I hope this helps?

Cor
 
Hi Paul,

First advice set in the top of your program Option Strict On, that shows a
lot of errors before runtime.

Here a sample, I could not see if you was using a treeview or a combobox
because your code was for a combobox in my opinion so I made two samples
(have a special look at that ToString)

I hope this helps?

Cor

\\\Sample table
Dim ds As New DataSet
Dim dt As New DataTable("McKenna")
ds.Tables.Add(dt)
dt.Columns.Add("Paul")
For i As Integer = i To 5
dt.Rows.Add(dt.NewRow)
dt.Rows.Item(i)(0) = Chr(i + 65)
Next
///
\\\
For Each row As DataRow In ds.Tables("McKenna").Rows
Me.TreeView1.Nodes.Add(row.Item("Paul").ToString)
Next
For Each row As DataRow In ds.Tables(0).Rows
Me.ComboBox1.Items.Add(row.Item(0))
Next
////
 
Back
Top