Hi,

In my DB I have 2 tables Units and Groups

In Units I have
Id
Name

In Groups I have
Id
Name
UnitID


This is my code

BMDataClassesDataContext db = new BMDataClassesDataContext();
 TreeNode rootNode = new TreeNode("BM");

            var n1 = from node in db.Units select node;


            foreach (var item in n1)
            {
                var child = new TreeNode(item.Name, item.Id.ToString());
                rootNode.ChildNodes.Add(child);
            }

            TreeView1.Nodes.Add(rootNode);

Now how can I add the table Group so it appears as a child node for the Unit Table?

Thnx beforehand,
batool

Recommended Answers

All 2 Replies

Just copy & run the code..But its in VB.net..U want this??

Option Strict On
Option Explicit On
Option Compare Text

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim lCount As Integer
            Dim tvw As TreeNode

            For lCount = 1 To 5
                tvw = TreeView1.Nodes.Add(lCount.ToString)
                tvw.Name = lCount.ToString
                Application.DoEvents()
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim findnode As TreeNode

            findnode = TreeView1.Nodes.Item("1")
            findnode.Nodes.Add("First")

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try

            Dim findnode As TreeNode

            findnode = TreeView1.Nodes.Item("2")
            findnode.Nodes.Add("Second")

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.