代码改到DataColChanging事件
Select Case e.DataCol.name
Case "仓库代码","物料编号","单位代码"
Dim filter As String
filter = "仓库代码" & IIF(e.DataRow.IsNull("仓库代码")," is null "," = '" & e.DataRow("仓库代码") & "'")
filter &= "and 物料编号" & IIF(e.DataRow.IsNull("物料编号")," is null "," = '" & e.DataRow("物料编号") & "'")
filter &= "and 单位代码" & IIF(e.DataRow.IsNull("单位代码")," is null "," = '" & e.DataRow("单位代码") & "'")
If not filter.Contains("=") Then Return
Dim dr As DataRow = e.DataRow
If e.DataTable.Find(filter) IsNot Nothing Then
MessageBox.Show("已经存在相同物料!","提示")
e.Cancel = True
End If
End Select