nodes and data in a treeview

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

I need a way to give each node an id number onto of what the text is being
displayed so i can access data in a database... how would i do this? this is
an example

RootNode (data: root)
+ Child1 (data: ID000001)
+ Child2 (data: ID000002)
+---ChildOfChild1 (data: ID0000003)

I thought tags would work by giving a structured data type as the object,
but i cant seem to figure out how to convert the tag back into the data...
any help or ideas would be real nice, thanks!
 
Hi Brian,

A XML file is not always a relational database, it passes it in its
possibilities.

Therefore it is not always possible to put a XML file in a database.

On the other hand can every so called relational database be put in a XML
file.

I hope this helps?

Cor
 
I could be totally wrong here, but I think he's not talking about XML. Just
an ordinary treeview.

When adding do something like this :
int id = 5;
TreeNode node = new TreeNode("Data ID" + id);
node.Tag = id;
treeview1.Nodes.Add(node);

Then when you need it just simply convert it :
int number = (int) treeview1.SelectedNode.Tag;

If the leading 0s are important you can use a string in stead of an int.

Yves
 
Hi Brian,

Phoenix(Yves) his sample is correct, but it is in C#

I made one in VB.net to correct my mistake

I hope this helps?

Cor

\\\Needs a treeview on a form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
TreeView1.BeginUpdate()
TreeView1.Nodes.Clear()
For i As Integer = 0 To 100
TreeView1.Nodes.Add(New TreeNode(i.ToString))
For y As Integer = 0 To 10
TreeView1.Nodes(i).Nodes.Add(Chr(y + 65))
TreeView1.Nodes(i).Nodes(y).Tag = i.ToString & Chr(y + 65)
Next
Next
TreeView1.EndUpdate()
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender _
As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles
TreeView1.AfterSelect
If Not TreeView1.SelectedNode.Tag Is Nothing Then
MessageBox.Show(TreeView1.SelectedNode.Tag.ToString)
End If
End Sub
///
 
yep not an XML file ;) I have a SQL Server backend hehe... but thanks for
the treeview info both of you.
 
Back
Top