代码放到DataColChanging事件
Select Case e.DataCol.Name
Case "规格","封装"
Dim dr As DataRow = e.DataRow
If dr.IsNull("规格") OrElse dr.IsNull("封装")Then
dr("查找列")= ""
Else
Dim dr1 As DataRow = e.DataTable.Find("规格 ='" & dr("规格") & "' and 封装 ='" & dr("封装") & "'")
If dr1 IsNot Nothing Then
MessageBox.Show(dr("规格") & "|" & dr("封装") & ":已有相同的物料封装")
e.Cancel = True
Return
End If
dr("查找列")=dr("规格") & "|" & dr("封装")
End If
end select