DataColChanged事件:
Select Case e.DataCol.Name
Case "日期A","日期B"
If e.DataRow.IsNull("日期A") OrElse e.DataRow.IsNull("日期B") Then
e.DataRow("日期AB列相隔时间") = Nothing
Else
Dim y,m,d As Integer
Dim d1 As Date = e.DataRow("日期A")
Dim d2 As Date = e.DataRow("日期B")
y = d2.Year - d1.Year
m = d2.Month - d1.Month
d = d2.day - d1.day
If m = 0 OrElse (m = 0 AndAlso d < 0) Then
y = y - 1
m = m + 12
End If
If d < 0 Then
m = m - 1
d = Date.DaysInMonth(d1.Year,d1.Month) + d
End If
Dim s As String
If y > 0 Then
s = y & "年"
End If
If m > 0 Then
s = s & m & "个月"
End If
If d > 0 Then
s = s & d & "日"
End If
e.DataRow("日期AB列相隔时间") = s
End If
End Select
[此贴子已经被作者于2010-11-30 9:10:10编辑过]