datagrid 只是一个前台控件。只要你绑定了记录集,单击 datagrid 的某一行,记录集就会自动定位。你利用这个记录集中的某个字段值,再查询得到一个新记录集,将其绑定在 datagrid2 即可。假定你在 DataGrid1 绑定的是 ADODC1,在 DataGrid2 绑定的是 rs:Private Sub DataGrig1_RowColChange(......) Set rs = ADODC1.Recordset.ActiveConnection.Execute("Select 生产单号 From 表 Where 物料 ='" & ADODC1.Recordset!物料 & "'") DataGrid2.Refresh End Sub
谢谢各位,已经解决了饿 rs_d2.CursorLocation = adUseClient If rs_d2.State <> 0 Then rs_d2.Close wuliaodaima = rs_allkucun.Fields("物料代码") rs_d2.Open "select t1.fstyleno as 款号, t2.fnumber as 物料代码,t2.fname as 物料名称,t2.ftotal from cj_ICBOM as t1 inner join cj_ICBOMCHILD as t2 on t1.FInterID=t2.FInterID where t2.fnumber='" + wuliaodaima + "'and State = 0", conn, adOpenKeyset, adLockOptimisticSet DataGrid2.DataSource = rs_d2 DataGrid2.ReBind DataGrid2.Refresh
1)抓取a
2)捞出a的生产单号
3)循环捞出单据信息
4)datagrid2.additem 要显示的信息
5)循环结束
6)datagrid1不可见,datagrid2可见
end sub
Set rs = ADODC1.Recordset.ActiveConnection.Execute("Select 生产单号 From 表 Where 物料 ='" & ADODC1.Recordset!物料 & "'")
DataGrid2.Refresh
End Sub
rs_d2.CursorLocation = adUseClient
If rs_d2.State <> 0 Then rs_d2.Close
wuliaodaima = rs_allkucun.Fields("物料代码")
rs_d2.Open "select t1.fstyleno as 款号, t2.fnumber as 物料代码,t2.fname as 物料名称,t2.ftotal from cj_ICBOM as t1 inner join cj_ICBOMCHILD as t2 on t1.FInterID=t2.FInterID where t2.fnumber='" + wuliaodaima + "'and State = 0", conn, adOpenKeyset, adLockOptimisticSet DataGrid2.DataSource = rs_d2
DataGrid2.ReBind
DataGrid2.Refresh