datacolchanged事件
If e.DataCol.Name = "身份证号码" Then '是身份证号码发生变化吗?
If e.DataRow.IsNull("身份证号码") Then '身份证号码是否为空
e.DataRow("出生日期") = Nothing '如果为空,则清除出生日期
Else
'否则从身份证号码列中提取出生日期
e.DataRow("出生日期") = ReadBirthday(e.DataRow("身份证号码"))
End If
ElseIf e.DataCol.name = "出生日期" Then
If e.newvalue <> Nothing Then
Dim y As Integer = e.NewValue.year
If format(e.newvalue, "MMdd") <= Format(Date.Today, "MMdd") Then
e.DataRow("年龄") = Date.Today.Year - y
Else
e.DataRow("年龄") = Date.Today.Year - y -1
End If
Else
e.DataRow("年龄") = Nothing
End If
End If