给你双击触发的例子
Private Sub DataGrid1_DblClick()
On Error Resume Next
Dim strsql As String
'向datagrid4中写入数据
txt_fkid.Text = ""
txt_jhid.Text = DataGrid1.Columns(0)
strsql = "select jh_id as ID,dw_mc as 单位名称,jh_sbmc as 设备名称,jh_gg as 规格型号,"
strsql = strsql & " jh_dw as 单位,jh_dj as 单价,jh_sl as 数量,jh_bfsl as 报废数量,jh_btsl as 补套数量,"
strsql = strsql & " jh_ptsl as 配套数量,jh_je as 金额,jh_bfje as 报废金额,jh_btje as 补套金额 ,jh_ptje as 配套金额,"
strsql = strsql & " jh_fl as 设备编码 ,jh_cj as 厂家 ,jh_hb as 货币 ,jh_bz as 备注 ,jh_year as 年份"
strsql = strsql & " from jhtz_dw_view"
strsql = strsql & " where jh_id=" & txt_jhid.Text
Set Db = New Connection
Db.CursorLocation = adUseClient
Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\计划管理系统.mdb;Persist Security Info=False"
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open strsql, Db, adOpenStatic, adLockOptimistic
Set DataGrid4.DataSource = adoPrimaryRS
DataGrid4.Columns(0).Visible = False
Set Db = Nothing
'如果fk_table里有和txt_jhid匹配的数据,那么在datagrid2中显示
strsql = "select * from jhtz_fk_view where jh_id=" & txt_jhid.Text
Set rs = ExecuteSQL(strsql, msgtext)
If rs.RecordCount > 0 Then
Do While Not rs.EOF
If txt_fkid.Text = "" Then
txt_fkid.Text = rs.Fields("fk_id")
Else
txt_fkid.Text = txt_fkid.Text & "," & rs.Fields("fk_id")
End If
rs.MoveNext
Loop
Else
txt_fkid.Text = ""
End If
strsql = "select fk_id as ID,fk_wczcje_bh as 完成资产流水号,fk_wczcje as 完成资产金额,fk_yfkje_bh as 预付款流水号, fk_yfkje as 预付款金额,fk_fkje_bh as 付款流水号,fk_fkje as 付款金额"
strsql = strsql & " from fk_table"
strsql = strsql & " where jh_id=" & txt_jhid.Text
Set Db = New Connection
Db.CursorLocation = adUseClient
Db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\计划管理系统.mdb;Persist Security Info=False"
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open strsql, Db, adOpenStatic, adLockOptimistic
Set DataGrid2.DataSource = adoPrimaryRS
DataGrid2.Columns(0).Visible = False
Set Db = Nothing
End Sub