vb6.0 怎么搜索Datagrid的内容,并将那一行选中?
全部代码:PrivateSubDataGrid1_RowColChange(LastRowAsVariant,ByValLastColAsInteger)Label5.C...
全部代码:Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)Label5.Caption = DataGrid1.Columns(0).CellText(DataGrid1.Bookmark)Label6.Caption = DataGrid1.Columns(1).CellText(DataGrid1.Bookmark)Label7.Caption = DataGrid1.Columns(2).CellText(DataGrid1.Bookmark)Label8.Caption = DataGrid1.Columns(3).CellText(DataGrid1.Bookmark)End SubPrivate Sub Form_Load()With Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\data.mdb;Jet OLEDB:Database Password=123456;".CommandType = adCmdUnknown.RecordSource = "SELECT * FROM sheet1".RefreshEnd WithSet DataGrid1.DataSource = Adodc1DataGrid1.Columns(1).Width = 2700DataGrid1.Columns(2).Width = 3800DataGrid1.Columns(3).Width = 900End Sub我想在文本框中输入要搜索的内容,然后一单击查找就搜索,并选中被搜索内容所在的哪一行,应该怎么弄?意思就是 :像Excel 的 ctrl+F 一样搜索 谢谢
展开
1个回答
展开全部
Private Sub Command1_Click() '宴差芹晌毕点击查找按钮
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Find "姓名 like '%" & Text1.Text & "%'"
If Adodc1.Recordset.EOF 庆老Then MsgBox "未找到!"
End Sub
追问
你好,若有相同的姓名,怎么继续查找下一个?当查找到最后一个后(也就是后面没有结果了),再次单击按钮提示“查找已完毕”?
追答
Private Sub Command1_Click() '点击查找按钮
Static flag As Boolean
If flag Then
Adodc1.Recordset.MoveNext
Else
Adodc1.Recordset.MoveFirst
flag = True
End If
If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.Find "姓名 like '%" & Text1.Text & "%'"
If Adodc1.Recordset.EOF Then
MsgBox "查找完毕!"
flag = False
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询