mpatram 0 Newbie Poster

Hi All,

I m working on a vb.net application. Having a form with treeview & datagrid control. My requirement is that I'll populate the treeview control from a SQL server table. I made this one.

The next task is to populate the datagrid control (another SQL Server Table) from a TreeNode Selection. I m not able to find any solution for this. can any one plz help me.

My code for populating the treeview from sql server table is given below

in Form_load
Dim strConn As String = "Server=BACKUPAEC;Database=DASE;Trusted_Connection=yes;" 'Connection String
Dim objConn As New SqlConnection(strConn) 'Conection Object

'Dataset Objects
Dim objDS As New DataSet
Dim objDS1 As New DataSet

'DataAdapters
Dim daMEquip1 As New SqlDataAdapter("SELECT distinct GroupName FROM MasterEquipmentConfig", objConn)
Dim daMEquip2 As New SqlDataAdapter("SELECT GroupName, EquipmentName, EquipmentID FROM MasterEquipmentConfig", objConn)

'Fill Dataset
daMEquip1.Fill(objDS, "MasterEquipmentConfig")
daMEquip2.Fill(objDS1, "MasterEquipmentConfig")

objConn.Close() 'Close Connection

Dim nodeGroup, nodeEquip As TreeNode
Dim rowGroup, rowEquip As DataRow

For Each rowGroup In objDS.Tables("MasterEquipmentConfig").Rows
nodeGroup = New TreeNode
nodeGroup.Text = rowGroup("GroupName")
nodeGroup.ForeColor = Color.Blue
TreeView1.Nodes.Add(nodeGroup)


For Each rowEquip In objDS1.Tables("MasterEquipmentConfig").Rows
If rowGroup("GroupName") = rowEquip("GroupName") Then
nodeEquip = New TreeNode
nodeEquip.Text = rowEquip("EquipmentName")
nodeGroup.Nodes.Add(nodeEquip)
End If
Next
Next

objDS.Dispose()
objDS1.Dispose()
daMEquip1.Dispose()
daMEquip2.Dispose()
objConn.Close()
objConn.Dispose()