前提:一、表产品型号与表产品配方根据列产品型号关联,克隆代码如下(能正常克隆):
Dim r As Row = Tables("产品型号").Current
Dim dnew As Row = Tables("产品型号").AddNew
Dim name As String = r("产品型号") & "_复件"
For Each c As Col In Tables("产品型号").Cols
If c.Name = "产品型号" Then
dnew(c.Name) = name
ElseIf c.Name <> "_Identify" Then
dnew(c.Name) = r(c.Name)
End If
Next
Dim drs As List(Of DataRow)
drs = r.DataRow.GetChildRows("产品配方")
Dim rc As DataRow
For Each dr As DataRow In drs
rc = dr.Clone
rc("产品型号") = name
Next
前提二、表产品型号中列产品型号禁止了重复,且表Datacolchanging属性中也写了如下禁止重复代码
If e.DataCol.Name = "产品型号" Then
Dim dr As DataRow
dr = e.DataTable.Find("产品型号 = '" & e.NewValue & "'")
If dr IsNot Nothing Then
MessageBox.Show("此产品型号已经存在!")
e.Cancel = True
End If
End If
问题:我用同一行点两次克隆行按钮,第一次成功,第二次不成功(因为禁止重复),但是关联表产品配方中依然克隆了关联行到第一次中;
我想解决的问题是:因重复克隆的时候没有成功,那么不克隆关联表中的行和当前克隆的行。
请大家帮忙,谢谢!