vb中如何获取datagrid选中行某个单元格的值?
OptionExplicitDimpanduanAsStringPrivateSubCommand1_Click()Dimrs_findbookAsNewADODB.Re...
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请高手指点!重谢 展开
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请高手指点!重谢 展开
展开全部
Private Sub DataGrid1_Click()
rs_findbook.Bookmark = DataGrid1.GetBookmark(0)
Label1.capiton=rs_findbook.field(7)
End Sub
rs_findbook.Bookmark = DataGrid1.GetBookmark(0)
Label1.capiton=rs_findbook.field(7)
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
DataGrid1.Col = 8 '第8列
a = DataGrid1.Text '当前行的第8列的值
a = DataGrid1.Text '当前行的第8列的值
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询