Hola amigos
Escribo para que me den una mano con como hacer para que al escribir en un textobox se filtre los datos en un datagrid y estando en el textbox al pulsar las teclas flecha arriba, flecha abajo, repág, avpág se desplace en las filas del datagrid (ojo sin salir del textbox).
Yo lo he hecho pero el tema es que no se ve que la fila completa del datagrid se pinte indicando que esta seleccionada una fila, espero dejarme entender. Les mostrare mi codigo y por favor ayudenme a como mejorarlo o que estoy haciendo mal.
Private sub txtData_Change()
If trim(txtData.Text) <> "" Then
Set RstData = Cnn.Execute("Select * From Productos Where Nombre Like '" & Trim(txtData.Text) & "%'"
Set dg.DataSource=RstData
If RstData.RecordCount > 0 then
dg.visible = True
dg.SetFocus
Else
dg.visible = False
End If
End if
End Sub
Private Sub dg_GotFocus()
'Refresco el DataGrid y Regreso el Foco al txtData
dg.Refresh
txtData.SetFocus
End Sub
¿Que me esta haciendo falta o que estoy haciendo mal?, ayudenme por favor
Saludos
9tnix
Siempre usar etiquetas [code](codigo)[/code]
Hola amigos depues de tanto reintentar la forma que funcione por fin di con la solucion.
La solucion estaba en que despues de la linea:
Set dg.DataSource=RstData
Yo le daba formato y ocultaba algunas columnas, claro si lo haces no permite hacer este truco, pero aqui les dejo mi solucion, espero que sea de ayuda para alguien:
Private sub txtData_Change()
Set RstLista = gCnn.Execute("Select IDProducto,Laboratorio,Nombre,U_Medida,PCom,PVen,PFra,Stock_F as Stock From
VProductos Where Nombre like '" & Trim(txtPro.Text) & "%' And Activo='SI'")
If RstLista.RecordCount > 0 Then
dg.Visible = True
Set dg.DataSource = RstLista
dg.Columns(0).Width = 900: dg.Columns(0).Caption = "ID"
dg.Columns(1).Width = 4000
dg.Columns(2).Width = 8100
dg.Columns(3).Width = 1800
dg.Columns(4).Width = 1000: dg.Columns(4).Alignment = dbgCenter
dg.Columns(4).NumberFormat = "#,##0.00"
dg.Columns(5).Width = 1000: dg.Columns(5).Alignment = dbgCenter
dg.Columns(5).NumberFormat = "#,##0.00"
dg.Columns(6).Width = 1000: dg.Columns(6).Alignment = dbgCenter
dg.Columns(6).NumberFormat = "#,##0.00"
dg.Columns(7).Width = 1000: dg.Columns(7).Alignment = dbgCenter
dg.SetFocus
Else
Set dg.DataSource = Nothing
dg.Visible = False
End If
End Sub
Private Sub txtDato_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
If dg.Visible Then
RstLista.MoveNext
If RstLista.EOF Then
RstLista.MoveLast
End If
dg.SetFocus
KeyCode = 0
End If
ElseIf KeyCode = vbKeyUp Then
If dg.Visible Then
RstLista.MovePrevious
If RstLista.BOF Then
RstLista.MoveFirst
End If
dg.SetFocus
KeyCode = 0
End If
End If
End Sub
Private Sub dg_GotFocus()
dg.Refresh
If txtDato.Enabled Then
txtDato.SetFocus
End If
End Sub
Me falta para usar las teclas Av. Pag y Av.RePag
Saludos
9tnix