你把这段代码赋值到 订单明细表 的datacolchanged事件去就行了。测试有效。
If e.DataCol.Name = "货品ID" Then
Dim pdr As DataRow = e.DataRow.GetParentRow("销售出库主表")
If pdr IsNot Nothing Then
Dim drs As List(of DataRow) = DataTables("销售出库主表").Select("客户名称 = '" & pdr("客户名称") & "' and _Identify <> " & pdr("_Identify"), "销售日期 desc")
For Each dr As DataRow In drs
Dim fdr As DataRow = e.DataTable.Find("销售单据编号='" & dr("_identify") & "' and 货品id = '" & e.NewValue & "'")
If fdr IsNot Nothing Then
e.DataRow("货品单价") = fdr("货品单价")
Exit For
End If
Next
End If
End If