不要管前面的按钮,最后点保存的时候重新保存树节点。
保存按钮代码
Dim dt As DataTable = DataTables("表B")
dt.DataRows.Clear
Dim dic As New Dictionary(of Integer, Integer)
Dim idx As Integer = 1
For Each nd As WinForm.TreeNode In tr.AllNodes
If nd.Text <> "全部" Then
If dic.ContainsKey(nd.Level) = False Then
dic.Add(nd.Level, idx)
Else
dic(nd.Level) = idx
End If
Dim ndr As DataRow = dt.AddNew
If nd.Level = 0 Then
ndr("父键") = Nothing
Else
ndr("父键") = dic(nd.Level - 1)
End If
ndr("键") = idx
ndr("标题") = nd.Text
idx += 1
End If
Next