将下面的代码设置在DataColChanged事件:
Select Case e.DataCol.Name Case "入库日期","出库日期" Dim dr As DataRow = e.DataRow If dr.IsNull("入库日期") OrElse dr.IsNull("出库日期") Then dr("库存时长") = Nothing Else Dim tp As TimeSpan = dr("出库日期") - dr("入库日期") dr("库存时长") = tp.TotalDays End IfEnd Select
参考这里的示例三:
http://www.foxtable.com/help/topics/1452.htm