以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何让一个工作表列的值变化后,另一个也跟着变化  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=58602)

--  作者:zhuzhi
--  发布时间:2014/10/20 16:51:00
--  [求助]如何让一个工作表列的值变化后,另一个也跟着变化
各位老师,我想实现一个功能,即工作表A的“第一列”的值变成“AAA”,则工作表B的“第一列”的值变成“BBC”

我什么也不懂,第一次看着帮助捣鼓代码,搞了半天,搞了这样一个东西:

Dim A As DataTable = DataTables("表A")
Dim AB As DataCol = A.DataCols("第一列")
Dim B As DataTable = DataTables("表B")
Dim BB As DataCol = A.DataCols("第一列")
If e.DataCol.name = "第一列" Then
 If e.NewValue = "AAA" Then
   BB("第一列").NewValue  = "BBC"
End If
End If

自然是什么也不通……我知道里面有很多关键概念都错了~~~~

不好意思,各位老师,请问如何用代码实现我想要的那个功能呢?

十分感谢!
-----------------------

我找到原因了!而且对于这个模块的原理也有了较深的理解,谢谢老师!

[此贴子已经被作者于2014-10-20 18:03:56编辑过]

--  作者:Bin
--  发布时间:2014/10/20 16:52:00
--  
http://www.foxtable.com/help/topics/1453.htm
--  作者:有点甜
--  发布时间:2014/10/20 16:54:00
--  

 参考,你必须确实是哪一行,才能修改的。

 

http://www.foxtable.com/help/topics/2490.htm

 


--  作者:zhuzhi
--  发布时间:2014/10/20 17:19:00
--  
老师,不好意思,我还是弄错了:

If e.DataCol = "第一列" Then
If e.NewValue = "AAA" Then
Dim dr As DataRow =DataTables("表B").Find("第一列 = \'" & dr("第一列") & "\'")
If dr IsNot Nothing Then
dr("第一列")="BBC"
End If
If e.NewValue = "ABA" Then
Dim dr As DataRow =DataTables("表B").Find("第一列 = \'" & dr("第一列") & "\'")
If dr IsNot Nothing Then
dr("第一列")="BBa"
End If
If e.NewValue = "ACA" Then
Dim dr As DataRow =DataTables("表B").Find("第一列 = \'" & dr("第一列") & "\'")
If dr IsNot Nothing Then
dr("第一列")="BBD"
End If
Next

一个 说If e.NewValue = "AAA" Then是错误用法,一个if没有用正确的end if作结。
请问,如何让代码能判断改变的值,当改变值是AAA,ABA,ACA,BBD时分别得到不同的值呢?

十分感谢!

--  作者:有点甜
--  发布时间:2014/10/20 17:34:00
--  
If e.DataCol = "第一列" Then
    Dim dr As DataRow =DataTables("表B").Find("第一列 = \'" & dr("第一列") & "\'")
    If dr IsNot Nothing Then
        If e.NewValue = "AAA" Then
            dr("第一列")="BBC"
        Else If e.NewValue = "ABA" Then
            dr("第一列")="BBa"
        Else If e.NewValue = "ACA" Then
            dr("第一列")="BBD"
        End If
    End If
End If

--  作者:zhuzhi
--  发布时间:2014/10/20 17:38:00
--  
谢谢老师,我有所感悟!
不过我刚才试验时,显示这样:

图片点击可在新窗口打开查看此主题相关图片如下:错误.jpg
图片点击可在新窗口打开查看


请问应该怎么做呢?

十分感谢!

--  作者:有点甜
--  发布时间:2014/10/20 17:39:00
--  
Dim dr As DataRow = e.DataRow
If e.DataCol.Name = "第一列" Then
    Dim dr As DataRow =DataTables("表B").Find("第一列 = \'" & dr("第一列") & "\'")
    If dr IsNot Nothing Then
        If e.NewValue = "AAA" Then
            dr("第一列")="BBC"
        Else If e.NewValue = "ABA" Then
            dr("第一列")="BBa"
        Else If e.NewValue = "ACA" Then
            dr("第一列")="BBD"
        End If
    End If
End If
[此贴子已经被作者于2014-10-20 17:39:52编辑过]

--  作者:zhuzhi
--  发布时间:2014/10/20 17:45:00
--  
老师,封闭块中隐藏变量是什么意思呀,说dr在封闭块中隐藏变量……

啊对不起,是我的错!
[此贴子已经被作者于2014-10-20 17:46:38编辑过]

--  作者:有点甜
--  发布时间:2014/10/20 17:47:00
--  
If e.DataCol.Name = "第一列" Then
    Dim dr As DataRow =DataTables("表B").Find("第一列 = \'" & e.DataRow("第一列") & "\'")
    If dr IsNot Nothing Then
        If e.NewValue = "AAA" Then
            dr("第一列")="BBC"
        Else If e.NewValue = "ABA" Then
            dr("第一列")="BBa"
        Else If e.NewValue = "ACA" Then
            dr("第一列")="BBD"
        End If
    End If
End If

--  作者:zhuzhi
--  发布时间:2014/10/20 17:55:00
--  
老师您好!可以正常放入表事件了,但我测试之后发现,似乎没有效果。
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.table

不好意思,能麻烦您看一看吗?
---------------

老师,我找到原因了,非常感谢!
[此贴子已经被作者于2014-10-20 18:04:32编辑过]