0

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

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by dnanetwork
0

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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.