vb中如何获取datagrid选中行某个单元格的值?

Option Explicit
Dim panduan As String
Private Sub Command1_Click()
Dim rs_findbook As New ADODB.Recordset
Dim sql As String
If Check1.Value = vbChecked Then
sql = "书名='" & Trim(Text1.Text & " ") & "'"
End If
If Check2.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "类别='" & Trim(Combo1.Text & " ") & "'"
Else
sql = sql & "and 书名='" & Trim(Combo1.Text & " ") & "'"
End If
End If
If Check3.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "作者='" & Trim(Text2.Text & " ") & "'"
Else
sql = sql & "and 作者='" & Trim(Text2.Text & " ") & "'"
End If
End If
If Check4.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "出版社='" & Trim(Text3.Text & " ") & "'"
Else
sql = sql & "and 出版社='" & Trim(Text3.Text & " ") & "'"
End If
End If
If Check5.Value = vbChecked Then
If Trim(sql) = "" Then
sql = "书籍编号='" & Trim(Text4.Text & " ") & "'"
Else
sql = sql & "and 书籍编号='" & Trim(Text4.Text & " ") & "'"
End If
End If
If Trim(sql) = "" Then
MsgBox "请选择查询方式!", vbOKOnly + vbExclamation
Exit Sub
End If
sql = "select * from 书籍信息 where " & sql
rs_findbook.CursorLocation = adUseClient
rs_findbook.Open sql, conn, adOpenKeyset, adLockPessimistic
DataGrid1.AllowAddNew = False
DataGrid1.AllowDelete = False
DataGrid1.AllowUpdate = False
Set DataGrid1.DataSource = rs_findbook
'rs_findbook.Close
End Sub
Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
book_num = DataGrid1.Columns(0).CellValue(DataGrid1.Bookmark)
panduan = DataGrid1.Columns(1).CellValue(DataGrid1.Bookmark)
End Sub
比如我单击第三行;那第三行的第8列的对应的单元格中的值是"PH005" 怎么能在下个窗体中的Label里显示PH005这个值?1请高手指点!重谢

是不是这样的 点击它过后 显示在label中 我这上是显示在combobox中的,是这样就hi我。

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-10-19
Private Sub DataGrid1_Click()
rs_findbook.Bookmark = DataGrid1.GetBookmark(0)
Label1.capiton=rs_findbook.field(7)
End Sub本回答被提问者采纳
第2个回答  2009-05-27
DataGrid1.Col = 8 '第8列
a = DataGrid1.Text '当前行的第8列的值
相似回答