以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  老师,还是一个目录树同步的问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=142760)

--  作者:cd_tdh
--  发布时间:2019/11/5 15:50:00
--  老师,还是一个目录树同步的问题

 新增节点后马上修改节点名称报错,如果是修改以前的节点就没问题。

 
此主题相关图片如下:qq截图20191105154957.png
按此在新窗口浏览图片

 


此主题相关图片如下:qq截图20191105154818.png
按此在新窗口浏览图片

 

导航表的 DataColChanged 事件代码如下:红色代码没执行

If e.DataCol.Name="分组"  Then
    Dim fn As winform.form=vars("editForm")
    If fn.Opened Then
        Dim tr As WinForm.TreeView = fn.Controls("TreeView1")
        For Each sd As  WinForm.TreeNode In tr.AllNodes
            If sd.Text = e.OldValue AndAlso sd.DataRow("子键")=e.DataRow("子键") Then
                sd.Text=e.NewValue

            End If
        Next
    End If
    Dim drs As List(Of  DataRow)
    drs = DataTables(vars("editTable")).Select("[分组] = \'" & e.OldValue & "\' and [子键] = \'" & e.DataRow("子键") &  "\'")
    For Each dr As DataRow In drs
        dr("分组") = e.NewValue
    Next
End If

If e.DataCol.Name="名称" Then
    Dim fn As winform.form=vars("editForm")
    If fn.Opened Then
        Dim tr As WinForm.TreeView = fn.Controls("TreeView1")
        For Each sd As  WinForm.TreeNode In tr.AllNodes
            If sd.Text = e.OldValue AndAlso sd.DataRow("序号")=e.DataRow("序号") Then
           msgbox(1)
                sd.Text=e.NewValue
           msgbox(2)
            End If
        Next
    End If
    Dim drs As List(Of  DataRow)
    drs = DataTables(vars("editTable")).Select("[名称] = \'" & e.OldValue & "\' and [序号] = \'" & e.DataRow("序号") &  "\'")
    For Each dr As DataRow In drs
        dr("名称") = e.NewValue
    Next
End If

 

  


[此贴子已经被作者于2019/11/5 15:51:57编辑过]

--  作者:有点蓝
--  发布时间:2019/11/5 16:02:00
--  
只有通过buildtree这种生成的树控件节点才有.DataRow属性,手工新建的节点肯定不会绑定到datarow的,所以sd.DataRow是不存在的。

只能使用一层层判断,先从分类名称找到第一层节点,再从分组名称找到第二层节点............

--  作者:cd_tdh
--  发布时间:2019/11/5 16:43:00
--  

请老师看看,还是不对

If e.DataCol.Name="分类" OrElse e.DataCol.Name="分组" OrElse  e.DataCol.Name="名称"  Then
    Dim fn As winform.form=vars("editForm")
    If fn.Opened Then
        Dim tr As WinForm.TreeView = fn.Controls("TreeView1")
        For Each sd As  WinForm.TreeNode In tr.AllNodes
            Select Case sd.Level
                Case 0
                    Dim dr As DataRow = DataTables(vars("editTable")).Find("[分类] Like \'%" & sd.Text & "\' and 分组 is null")
                    If dr IsNot Nothing Then
                        If sd.Text = e.OldValue AndAlso dr("父键")=e.DataRow("父键")  Then
                        sd.Text= e.NewValue
                        End If
                    End If
                    Dim drs As List(Of  DataRow)
                    drs = DataTables(vars("editTable")).Select("[分类] = \'" & e.OldValue & "\' and [父键] = \'" & e.DataRow("父键") &  "\'")
                    For Each dr1 As DataRow In drs
                        dr1("分类") = e.NewValue
                    Next
                Case 1
                    Dim dr As DataRow = DataTables(vars("editTable")).Find("[分类] Like \'%" & sd.parentnode.Text & "\' and 分组 = \'" & sd.Text & "\' and 名称 is null")
                    If dr IsNot Nothing Then
                        If sd.Text = e.OldValue  AndAlso dr("子键")=e.DataRow("子键")  Then
                        sd.Text= e.NewValue
                        End If
                    End If
                    Dim drs As List(Of  DataRow)
                    drs = DataTables(vars("editTable")).Select("[分组] = \'" & e.OldValue & "\' and [子键] = \'" & e.DataRow("子键") &  "\'")
                    For Each dr2 As DataRow In drs
                        dr2("分组") = e.NewValue
                    Next
                Case 2
                    Dim dr As DataRow = DataTables(vars("editTable")).Find("[分类] Like \'%" & sd.parentnode.parentnode.Text & "\' and 分组 = \'" & sd.parentnode.Text & "\' and 名称 = \'" & sd.Text & "\'")
                    If dr IsNot Nothing Then
                        If sd.Text = e.OldValue AndAlso dr("序号")=e.DataRow("序号")  Then
                            sd.Text=e.NewValue
                        End If
                    End If
                    Dim drs As List(Of  DataRow)
                    drs = DataTables(vars("editTable")).Select("[名称] = \'" & e.OldValue & "\' and [序号] = \'" & e.DataRow("序号") &  "\'")
                    For Each dr3 As DataRow In drs
                        dr3("名称") = e.NewValue
                    Next
            End Select
        Next
    End If
End If

[此贴子已经被作者于2019/11/5 17:02:36编辑过]

--  作者:有点蓝
--  发布时间:2019/11/5 17:05:00
--  
If e.DataCol.Name="名称" Then
    Dim fn As winform.form=vars("editForm")
    If fn.Opened Then
        Dim tr As WinForm.TreeView = fn.Controls("TreeView1")
        Dim node As WinForm.TreeNode = tr.Nodes(e.DataRow("分类"))
        If node IsNot Nothing andalso node.Nodes.count > 0 Then
            node = node.Nodes(e.DataRow("分组"))
            If node IsNot Nothing andalso node.Nodes.count > 0  Then
                node = node.Nodes(e.OldValue)
                If node IsNot Nothing Then
                    node .Text=e.NewValue
                End If
            End If
        End If
    End If
    Dim drs As List(Of  DataRow)
    drs = DataTables(vars("editTable")).Select("[名称] = \'" & e.OldValue & "\' and [序号] = \'" & e.DataRow("序号") &  "\'")
    For Each dr As DataRow In drs
        dr("名称") = e.NewValue
    Next
End If


--  作者:cd_tdh
--  发布时间:2019/11/5 17:14:00
--  

.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2019.10.26.1
错误所在事件:表,导航,DataColChanged
详细错误信息:
调用的目标发生了异常。
未将对象引用设置到对象的实例。

老师,报错,4就没出来!

 

 

If e.DataCol.Name="名称" Then
    Dim fn As winform.form=vars("editForm")
msgbox(1)
    If fn.Opened Then
        Dim tr As WinForm.TreeView = fn.Controls("TreeView1")
msgbox(2)
        Dim node As WinForm.TreeNode = tr.Nodes(e.DataRow("分类"))
msgbox(3)
        If node IsNot Nothing AndAlso node.Nodes.count > 0 Then
            node = node.Nodes(e.DataRow("分组"))
msgbox(4)

            If node IsNot Nothing AndAlso node.Nodes.count > 0  Then
                node = node.Nodes(e.OldValue)
msgbox(5)
                If node IsNot Nothing Then
                    node .Text=e.NewValue
msgbox(6)
                End If
            End If
        End If
    End If
msgbox(7)

[此贴子已经被作者于2019/11/5 17:17:21编辑过]

--  作者:有点蓝
--  发布时间:2019/11/5 17:40:00
--  
msgbox(3)
        If node IsNot Nothing AndAlso node.Nodes.count > 0 Then
msgbox(node.text)
msgbox(node.Nodes.Count)
msgbox(e.DataRow("分组"))
            node = node.Nodes(e.DataRow("分组"))
msgbox(4)

--  作者:cd_tdh
--  发布时间:2019/11/6 9:30:00
--  

老师,3后面的代码没执行,直接就报错,报错的原因好像是这样的:

 

 
图片点击可在新窗口打开查看此主题相关图片如下:qq截图20191106095744.png
图片点击可在新窗口打开查看

[此贴子已经被作者于2019/11/6 10:21:18编辑过]

--  作者:有点蓝
--  发布时间:2019/11/6 10:20:00
--  
dim s as string = e.DataRow("分类")
tr.Nodes(s.trim())
--  作者:cd_tdh
--  发布时间:2019/11/6 10:33:00
--  

老师,数据正常了,在新增节点时,OldValue为空,还没有(node = node.Nodes(e.OldValue))这个节点,执行到6报这个错是什么原因?

 


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20191106102711.png
图片点击可在新窗口打开查看

 

msgbox(1)
        Dim s As String = e.DataRow("分类")
msgbox(2)
        Dim node As WinForm.TreeNode = tr.Nodes(s.trim())
msgbox(3)
        If node IsNot Nothing AndAlso node.Nodes.count > 0 Then
msgbox(4)
            node = node.Nodes(e.DataRow("分组"))
msgbox(5)
            If node IsNot Nothing AndAlso node.Nodes.count > 0  Then
msgbox(6)
                node = node.Nodes(e.OldValue)
msgbox(7)
                If node IsNot Nothing Then
msgbox(8)
                    node .Text=e.NewValue
msgbox(9)
                End If

[此贴子已经被作者于2019/11/6 10:47:36编辑过]

--  作者:有点蓝
--  发布时间:2019/11/6 10:43:00
--  
msgbox(5)
            If node IsNot Nothing AndAlso node.Nodes.count > 0 andalso e.OldValue > "" Then
msgbox(6)
                node = node.Nodes(e.OldValue)
msgbox(7)