Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

search a node and count the child nodes in treeview

its very urgent plz help me.... when i select a particular node in a combobox it should search that node and display only that node and corresponding childnodes in the treeview and also it should count the number of childnodes in that parent node if any one know the code for this plz give the code
thank u




Dim xSelNodeId As String ' storing clicked node key
Dim xCn As New ADODB.Connection ' record set
Dim xTimerInterval As Integer ' timer delay
Dim xConStr As String ' database path


Private Sub cmdAdd_Click()
Call local_saveNode
End Sub

Private Sub local_saveNode()
'***************************
'* saving node in database *
'***************************
Dim sqlQry As String
Dim xLevel As Integer
Dim xNodeId As String
Dim xRsTemp2 As New ADODB.Recordset
Dim xChildOf As String
Dim xNewNodeText As String
If Trim(txtNode.Text) = "" Then
MsgBox "Enter Text"
txtNode.SetFocus
Exit Sub
End If

sqlQry = ""
xChildOf = ""
xNewNodeText = txtNode.Text
xNodeId = local_generateNumber

txtNode.Text = "Wait..............."
If Trim(xSelNodeId) = "a" Then
xLevel = 1
xChildOf = xSelNodeId
Else
sqlQry = "select * from tblNodes where nodeId = '" & xSelNodeId & "'"
xRsTemp2.Open sqlQry, xConStr, adOpenDynamic, adLockOptimistic
With xRsTemp2
xLevel = .Fields("nodeLevel") + 1
xChildOf = xSelNodeId
xRsTemp2.Close
End With
End If

sqlQry = ""
sqlQry = "insert into tblNodes (nodeId, nodeText, nodeLevel, childOf) values " & _
"('" & xNodeId & "', '" & xNewNodeText & "'," & xLevel & ", '" & xChildOf & "')"
xCn.Open xConStr
xCn.Execute (sqlQry)
Set xRsTemp2 = Nothing
xCn.Close


tmrTv.Interval = 1000

End Sub

Private Sub CmdEnd_Click()
End
End Sub

Private Sub cmdRefresh_Click()
Call local_fillTreeView
End Sub

Private Sub Form_Load()

xSelNodeId = "a"

xTimerInterval = 0
xConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "accounts.mdb;Persist Security Info=False"
With imgNode
.ImageHeight = 16
.ImageWidth = 16
.ListImages.Add 1, "close", LoadPicture(App.Path & "close.bmp")
.ListImages.Add 2, "open", LoadPicture(App.Path & "open.bmp")
.ListImages.Add 3, "file", LoadPicture(App.Path & "leaf.bmp")
End With
Call local_fillTreeView

End Sub

Private Sub local_fillTreeView()
'****************************
' showing nodes in TreeView *
'****************************
Dim sqlQry As String
Dim xNode As Node
Dim xRsTemp1 As New ADODB.Recordset
Dim xParent As String

trV.Nodes.Clear


Set xNode = trV.Nodes.Add(, , "a", "Main Root", 2)
xNode.Expanded = True
sqlQry = ""
sqlQry = "select * from tblNodes order by nodeLevel, nodeText asc" ' where nodeLevel=1"
xRsTemp1.Open sqlQry, xConStr, adOpenDynamic, adLockOptimistic
With xRsTemp1
If Not .BOF Or Not .EOF Then
Do While Not .EOF
xParent = .Fields("childOf")
Set xNode = trV.Nodes.Add(xParent, tvwChild, .Fields("nodeId"), .Fields("nodeText"), 1)
.MoveNext
Loop
End If
.Close
End With
'*****************************************
'* node have not child displayed as file *
'*****************************************
For Each xNode In trV.Nodes
If xNode.Children = 0 Then
xNode.Image = 3
End If
Next
End Sub

Private Function local_generateNumber() As String
Dim xRs3 As New ADODB.Recordset
Dim sqlQry As String
Dim xNewNum As String
Dim xNum As Long
Dim xZero As Integer
Dim xAddZero As String
sqlQry = ""
sqlQry = "select max(nodeId) as xId from tblNodes"
xRs3.Open sqlQry, xConStr, adOpenDynamic, adLockOptimistic
With xRs3
If IsNull(.Fields("xId")) Then
xNum = 1
Else
xNum = Trim(CLng(Right(.Fields("xId"), 9))) + 1
End If
.Close
End With
xZero = 9 - Len(Trim(xNum))
xAddZero = ""
For x = 1 To xZero
xAddZero = xAddZero & "0"
Next
xNewNum = "a" & xAddZero & xNum
local_generateNumber = xNewNum
End Function

Private Sub tmrTv_Timer()
'********************************************
'* treeview will be refresh after 2 seconds *
'********************************************
xTimerInterval = xTimerInterval + 1
If xTimerInterval = 2 Then
Call local_fillTreeView
txtNode.Text = ""
tmrTv.Interval = 0
xTimerInterval = 0
End If
End Sub

Private Sub trV_Collapse(ByVal Node As MSComctlLib.Node)
If Node.Children <> 0 Then
Node.Image = 1
End If
End Sub


Private Sub trV_Expand(ByVal Node As MSComctlLib.Node)
If Node.Children = 0 Then
Node.Image = 3
Else
Node.Image = 2
End If
End Sub


Private Sub trV_NodeClick(ByVal Node As MSComctlLib.Node)
xSelNodeId = Node.Key
End Sub


Sign In or Register to comment.