Code:
[+] Parent 1 (GRedBr=1,GParent=0)
--- Child 1 (GRedBr=4,GParent=1)
[+] Child 2 (GRedBr=5,GParent=1)
--- SubChild 2-1 (GRedBr=7,GParent=5)
--- SubChild 2-2 (GRedBr=8,GParent=5)
[+] Parent 2 (GRedBr=2,GParent=0)
--- Child 3 (GRedBr=3,GParent=2)
--- Child 4 (GRedBr=6,GParent=2)
[+] Parent 1 (GRedBr=1,GParent=0)
--- Child 1 (GRedBr=4,GParent=1)
[+] Child 2 (GRedBr=5,GParent=1)
--- SubChild 2-1 (GRedBr=7,GParent=5)
--- SubChild 2-2 (GRedBr=8,GParent=5)
[+] Parent 2 (GRedBr=2,GParent=0)
--- Child 3 (GRedBr=3,GParent=2)
--- Child 4 (GRedBr=6,GParent=2)
Ovo GRedBr i GParent su polja u mdb-u.
Imam 2 button-a ("Upis grupe","Upis podgrupe")
Funkcionise na sledeci nacin :
- kada kliknem na "Upis grupe" tada se radi o Root node-u
- kada kliknem na "Upis podgrupe" upisuje se kao child node u prethodno selektovanom node-u
Radi se o tome da ih prvo zapisujem (jedan po jedan) u bazu pa tek onda vrsim popunjavanje treeview-a
evo koda :
Code:
Private Sub tv1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tv1.SelectedNodeChanged
Session.Item("SelGRP") = CLng(tv1.SelectedNode.Value.ToString)
End Sub
Private Sub btnSnimi_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSnimi.Click
'vrsi se snimanje u naziva grupe u bazu
'mdb im polja : GRedBr, GParent, GNaziv
'gde je GRedBr redni broj zapisa, GParent je 0 ako se radi o root-u ili redni broj selektovanog, Parent, noda ako se radi o child
Listaj()
End Sub
Public Sub Listaj()
tv1.Nodes.Clear()
Session.Item("strSql") = "SELECT * FROM Grupe ORDER BY GParent ASC, GRedBr ASC;"
'sortiranje vrsim na ovaj nacin da bi se hijerarhijskim redosledom popunjavao treeview
OpenDB()
cmd = New SqlCommand(Session.Item("strSql").ToString, conn)
tds = cmd.ExecuteReader
If tds.HasRows = True Then
Do While tds.Read
'ubacivanje root node-a
If tds("GParent") = 0 Then
Dim nd As New TreeNode(tds("GNaziv"), tds("GRedBr").ToString)
tv1.Nodes.Add(nd)
Else
'ubacivanje child node-a - OVDE SE JAVLJA PROBLEM
For Each td As TreeNode In tv1.Nodes
If td.Value.ToString = tds("GParent").ToString Then
Dim nd As New TreeNode(tds("GNaziv"), tds("GRedBr").ToString)
td.ChildNodes.Add(nd)
Exit For
End If
Next
End If
Loop
End If
tds.Close() : tds = Nothing : cmd.Dispose() : cmd = Nothing : conn.Close() : conn.Dispose() : conn = Nothing
tv1.CollapseAll()
If Session.Item("SelGRP") > 0 Then
lblSelGRP.Text = Session.Item("SelGRP").ToString
For Each ts As TreeNode In tv1.Nodes
If ts.Value.ToString = Session.Item("SelGRP").ToString Then
Try
ts.Expand()
Catch ex As Exception
End Try
Exit For
End If
Next
End If
End Sub
Private Sub tv1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tv1.SelectedNodeChanged
Session.Item("SelGRP") = CLng(tv1.SelectedNode.Value.ToString)
End Sub
Private Sub btnSnimi_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSnimi.Click
'vrsi se snimanje u naziva grupe u bazu
'mdb im polja : GRedBr, GParent, GNaziv
'gde je GRedBr redni broj zapisa, GParent je 0 ako se radi o root-u ili redni broj selektovanog, Parent, noda ako se radi o child
Listaj()
End Sub
Public Sub Listaj()
tv1.Nodes.Clear()
Session.Item("strSql") = "SELECT * FROM Grupe ORDER BY GParent ASC, GRedBr ASC;"
'sortiranje vrsim na ovaj nacin da bi se hijerarhijskim redosledom popunjavao treeview
OpenDB()
cmd = New SqlCommand(Session.Item("strSql").ToString, conn)
tds = cmd.ExecuteReader
If tds.HasRows = True Then
Do While tds.Read
'ubacivanje root node-a
If tds("GParent") = 0 Then
Dim nd As New TreeNode(tds("GNaziv"), tds("GRedBr").ToString)
tv1.Nodes.Add(nd)
Else
'ubacivanje child node-a - OVDE SE JAVLJA PROBLEM
For Each td As TreeNode In tv1.Nodes
If td.Value.ToString = tds("GParent").ToString Then
Dim nd As New TreeNode(tds("GNaziv"), tds("GRedBr").ToString)
td.ChildNodes.Add(nd)
Exit For
End If
Next
End If
Loop
End If
tds.Close() : tds = Nothing : cmd.Dispose() : cmd = Nothing : conn.Close() : conn.Dispose() : conn = Nothing
tv1.CollapseAll()
If Session.Item("SelGRP") > 0 Then
lblSelGRP.Text = Session.Item("SelGRP").ToString
For Each ts As TreeNode In tv1.Nodes
If ts.Value.ToString = Session.Item("SelGRP").ToString Then
Try
ts.Expand()
Catch ex As Exception
End Try
Exit For
End If
Next
End If
End Sub
Rezultat procedure navedene u ovom primeru : izvrsi popunjavanje root node-a, izvrsi ubacivanje svih Child node-a u pripadajuci Parent ali ne izvrsi ubacivanje SubChild node-a u Child 2 node.
Takodje, ne izvrsi se Expand selektovanog node-a.
Znaci, izvrsi se, hijerarhiski gledano, ubacivanje svih root (parent) node-a i 1. reda child node-a ali ne i 2.reda (SubChild 2-1 i SubChild 2-2).
Da li neko zna u cemu je problem?
Problem se javlja i u drugom delu koda, jer se ne izvrsi Expand selektovanog Parent node-a (ima svoje child-ove, znaci trebalo bi).
Unapred hvala svima na odgovorima, sugestijama.
Pozdrav svima.