Visual Basic - Busqueda en un FlexGrid o DataGrid

Life is soft - evento anual de software empresarial
 
Vista:

Busqueda en un FlexGrid o DataGrid

Publicado por juana (32 intervenciones) el 15/07/2008 18:25:24
Hola!!
Necesito generar un formulario con un DataGrid o FlexGrid y un campo de texto y cuando escribo en el campo de texto se realice una búsqueda en el DataGrid o FlexGrid y se de foco a la línea que corresponda con los datos incluidos en el campo de texto.

Gracias!!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Busqueda en un FlexGrid o DataGrid

Publicado por Efren Morales (1 intervención) el 26/03/2009 00:02:10
Pon esto en un Modulo
Public Function AutoComplete(sTextbox As TextBox, sFlexGrid As MSFlexGrid, sDB As Database, sTable As String, sField As String) As Boolean
On Error Resume Next
Dim sCounter As Integer
Dim OldLen As Integer
Dim sTemp As Recordset
'Set AutoComplete function to FALSE
AutoComplete = False
If Not sTextbox.Text = "" And IsDelOrBack = False Then
'Set OldLen as the sTextbox lenght
OldLen = Len(sTextbox.Text)
Set sTemp = sDB.OpenRecordset("SELECT * FROM " & sTable & " WHERE " & sField & " LIKE '" & sTextbox.Text & "*'", dbOpenDynaset)
If Err = 3075 Then
'Here we got a bug!!
End If
If Not sTemp.RecordCount = 0 Then
If sTemp.EOF = True And sTemp.BOF = True Then
MsgBox "Not Matching Records", vbInformation, "Error"
Else
sTemp.MoveFirst
sFlexGrid.Clear
sFlexGrid.FormatString = "Artist | CD Name | Price | Reference"
Do While Not sTemp.EOF
sFlexGrid.AddItem sTemp.Fields(1).Value
sFlexGrid.TextMatrix(sFlexGrid.Rows - 1, 1) = sTemp.Fields(2).Value
sFlexGrid.TextMatrix(sFlexGrid.Rows - 1, 2) = sTemp.Fields(5).Value
sFlexGrid.TextMatrix(sFlexGrid.Rows - 1, 3) = sTemp.Fields(4).Value
sTemp.MoveNext
Loop
End If
If sTextbox.SelText = "" Then
sTextbox.SelStart = OldLen
Else
sTextbox.SelStart = InStr(sTextbox.Text, sTextbox.SelText)
End If
sTextbox.SelLength = Len(sTextbox.Text)
AutoComplete = True
Else
sFlexGrid.Clear
End If
End If
End Function

Esto en un Formulario esta bueno

Private Sub Form_Load()
With cboBusqueda
.AddItem "Artist"
.AddItem "CD Name"
.ListIndex = 0
End With
If Right(App.Path, 1) = "" Then
Set DB = OpenDatabase(App.Path + "DB.mdb")
Else
Set DB = OpenDatabase(App.Path + "DB.mdb")
End If
Set Rs = DB.OpenRecordset("ListaCDs")
End Sub
Private Sub mnuAbout_Click()
frmAbout.Show
End Sub

Private Sub TextoaBuscar_Change()
On Error Resume Next
If cboBusqueda.Text <> "" Then
FlexResultado.Rows = 1
If FlexResultado.Rows = 1 Then
FlexResultado.TextMatrix(0, 0) = "Artist"
FlexResultado.TextMatrix(0, 1) = "CD Name"
FlexResultado.TextMatrix(0, 2) = "Price"
FlexResultado.TextMatrix(0, 3) = "Reference"
End If
Select Case cboBusqueda.Text
Case "Artist"
AutoComplete TextoaBuscar, FlexResultado, DB, "ListaCDs", "Artista"
Case "CD Name"
AutoComplete TextoaBuscar, FlexResultado, DB, "ListaCDs", "Disco"
Case Else
End Select
Else
TextoaBuscar = ""
cboBusqueda.ListIndex = 0
End If
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar