以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]BeforeAddDataRow代码问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=127372)

--  作者:cqlwsam
--  发布时间:2018/11/12 17:55:00
--  [求助]BeforeAddDataRow代码问题
如图:


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

运行后出现的问题:


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



BeforeAddDataRow代码:


\'\'\'

Dim frm As WinForm.Form = Forms("行政区域库维护")

If frm.Opened = False Then

    frm.open()

End If


Dim txt As String = frm.Controls("TextBox6").text

Dim txt1 As String

If txt="" Then

    MessageBox.show("信息添加前需选择检索字段录入检索词确认库中无相同信息后进行,以避免重复!","提示",MessageBoxButtons.OK,MessageBoxIcon.Question)

    e.Cancel = True

Else

    MessageBox.show("txt:" & txt)

    For Each c As WinForm.Control In frm.Controls

        If Typeof c Is WinForm.RadioButton Then \'判断控件是否是单选框

            Dim t As WinForm.RadioButton = c \'使用特定类型的变量引用控件

            If t.checked Then

                txt1= t.Text

            End If

        End If

    Next

    MessageBox.show(txt1)


    Dim dr As DataRow = e.DataTable.Find("[" & txt1 & "] =\'" & txt & "\'")

    If dr Is Nothing Then \'如果找到的话

       e.DataRow(txt1) =txt

    Else

        MessageBox.Show("表中有相同的行政信息,请重新选择检索字段录入检索词并确认无相同的内容后进行,以避免重复!","提示",MessageBoxButtons.OK,MessageBoxIcon.Question)

        e.cancel =True

    End If

End If


前后都能通过,拉黄的有问题。



--  作者:cqlwsam
--  发布时间:2018/11/12 18:19:00
--  
是不是需要将拉黄的部分写在其它事件中。
--  作者:有点甜
--  发布时间:2018/11/12 19:11:00
--  
代码应该写到 datarowadding 或者 datarowadded 事件
--  作者:cqlwsam
--  发布时间:2018/11/12 20:11:00
--  
分开写,赋值写在datarowadding 或者datarowadded事件中。是否添加的判断写在beforeadddatarow事件中。
谢谢!

--  作者:有点甜
--  发布时间:2018/11/13 9:19:00
--  
以下是引用cqlwsam在2018/11/12 20:11:00的发言:
分开写,赋值写在datarowadding 或者datarowadded事件中。是否添加的判断写在beforeadddatarow事件中。
谢谢!

 

分开写最好。你也可以在datarowadded事件那里,如果不符合,就删除当前行。