| Author: Pradeep Kumar Chaudhary 30 Aug 2008 | Member Level: Gold | Rating: Points: 6 |
Dim N As TreeNode
'Method 1: straightforward adding of nodes With Me.TreeView1.Nodes 'add text .Add("AddByText") 'since with..end with is used: read TreeView1.Nodes.Add ....
'every add method returns the newly created node. You can use 'this concept set the result to a variable or to directly add 'a childnode: .Add("AddByText2").Nodes.Add("ChildOfAddByText")
'this, you can take as far as you want .Add("AddByText3").Nodes.Add("ChildOfAddByText").Nodes.Add("Another child")
'-- N = .Add("AddByText, Attach To Variable") N.Nodes.Add("Child one") N.Nodes.Add("Child two") ' -- With .Add("AddByText Use WithTo Add ChildNodes").Nodes .Add("Child 1") .Add("Child 2") .Add("Child 3").Nodes.Add("Subchild 1") End With End With
|
| Author: UltimateRengan 01 Sep 2008 | Member Level: Diamond | Rating: Points: 6 |
hi, Take this example
Imports System.Data Imports System.Data.SqlClient Partial Class _Default Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then BindData() End If
End Sub Sub BindData() Dim strConn As String strConn = "USER=asdf;PASSWORD=iiii;SERVER=jjj;DATABASE=Emp" Dim MySQL As String = "Select x,empno, jj from x" Dim MyConn As New SqlClient.SqlConnection(strConn) Dim ds As DataSet = New DataSet() Dim Cmd As New SqlClient.SqlDataAdapter(MySQL, MyConn) Cmd.Fill(ds, "Emptbl") 'Fill the TreeView control Nodes using For Loop For Each Row As DataRow In ds.Tables("Emptbl").Rows Dim TNode As New TreeNode("First") TreeView1.Nodes.Add(TNode) Dim CNode1 As New TreeNode(Row("x")) TNode.ChildNodes.Add(CNode1) Dim CNode2 As New TreeNode(Row("empno")) TNode.ChildNodes.Add(CNode2) Dim CNode3 As New TreeNode(Row("jj")) TNode.ChildNodes.Add(CNode3) TNode.CollapseAll() Next End Sub End Class
|