1 ضمیمه
نقل قول: Treeview and Mysql
اگه امکانش هست ساختار جدول تون رو تغییر بدید. نیازی هم نیست جدولی که میخواهید از تابع برگردونده بشه Using کنید. موردی رو Using کنید که میخواهید در همون تابع ایجاد و نابود بشه.
ضمیمه 151111
Public Sub Fill_Node_Tree()
Tview_Nodes.Nodes.Clear()
Dim dict As New Dictionary(Of Integer, TreeNode)
For Each row As Data.DataRow In GetProject_tree().Rows
Dim id As Integer = row.Item(0)
Dim itemName As String = row.Item(1)
Dim parentId As Integer = IIf(row.Item(2) Is DBNull.Value, -1, row.Item(2))
Dim node As New TreeNode(itemName)
node.Name = id
node.Tag = parentId
dict.Add(id, node)
If parentId = -1 Then
Tview_Nodes.Nodes.Add(node)
End If
Next
For Each item In dict.Values
If dict.ContainsKey(item.Tag) Then
dict(item.Tag).Nodes.Add(item)
End If
Next
Tview_Nodes.ExpandAll()
End Sub
Public Function GetProject_tree() As DataTable
Dim dt As New DataTable
Dim conString As String = String.Format("server={0}; user id={1}; password={2}; database={3}; pooling=false", server, userName, password, DatabaseName)
Using con As New MySqlConnection(conString)
Using cmd As New MySqlCommand("SELECT id, item_name, parent_id FROM Project_tree;", con)
Using sda As New MySqlDataAdapter(cmd)
sda.Fill(dt)
Return dt
End Using
End Using
End Using
End Function
End Class
نقل قول: Treeview and Mysql
سپاس، ساختار دیتابیسم رو تغییر دادم عالی و بدون نقص اجرا میشه. ممنون