Select Case e.DataCol.name
Case "年月"
If e.NewValue > “” AndAlso e.DataRow.IsNull("姓名") = False
Dim dr As DataRow = e.DataRow
If e.DataTable.Find("年月 = '" & e.NewValue & "' And 姓名 =" & dr("姓名")) IsNot Nothing Then
MessageBox.Show("已经存在相同年月和姓名的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
e.Cancel = True
End If
End If
Case "姓名"
If e.DataRow.IsNull("姓名") = False AndAlso e.DataRow.IsNull("年月") = False
Dim dr As DataRow = e.DataRow
If e.DataTable.Find("年月 = '" & dr("年月") & "' And 姓名 = " & e.NewValue ) IsNot Nothing Then
MessageBox.Show("已经存在相同年月和姓名的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
e.Cancel = True
End If
End If
End Select
上面的代码是不允许输入相同的数据行的,但是放在datacolchanging 里面不起作用。为什么?