Visual Basic - Autocompletar DBCombo

Life is soft - evento anual de software empresarial
 
Vista:

Autocompletar DBCombo

Publicado por Mike (2 intervenciones) el 24/04/2007 15:59:16
Amigos:
Recien me inicio en visual basic y no encuentro la forma de autocompletar o búsqueda por aproximación en un DBCombo a medida que se escribe un texto.
Si alguien conoce la forma, se lo agradeceré .
Saludos
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:Autocompletar DBCombo

Publicado por Valli (28 intervenciones) el 30/04/2007 13:04:25
Prueba con esto haber si te sirve.
Este ejemplo no esta hecho con un DBCOMBO, esta con un ComboBox, pero donde aparezca el nombre del control lo cambias por el tuyo y te sirve igual.

Escribe el siguiente código en el form que contenga el Combo:

Private Sub Combo1_Change(Index As Integer)
Static YaEstoy As Boolean

If Not YaEstoy Then
YaEstoy = True
unCombo_Change Combo1(Index).Text, Combo1(Index)
YaEstoy = False
End If
Err = 0
End Sub

Private Sub Combo1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
unCombo_KeyDown KeyCode
End Sub

Private Sub Combo1_KeyPress(Index As Integer, KeyAscii As Integer)
unCombo_KeyPress KeyAscii
End Sub

Añade estas declaraciones y procedimientos en un módulo BAS,
(o en el mismo FORM, pero cambia el PUBLIC por PRIVATE):

Option Explicit

Dim Combo1Borrado As Boolean

Public Sub unCombo_KeyDown(KeyCode As Integer)
If KeyCode = vbKeyDelete Then
Combo1Borrado = True
Else
Combo1Borrado = False
End If
End Sub

Public Sub unCombo_KeyPress(KeyAscii As Integer)
'si se pulsa Borrar... ignorar la búsqueda al cambiar
If KeyAscii = vbKeyBack Then
Combo1Borrado = True
Else
Combo1Borrado = False
End If
End Sub

Public Sub unCombo_Change(ByVal sText As String, elCombo As ComboBox)
Dim i As Integer, L As Integer

If Not Combo1Borrado Then
L = Len(sText)
With elCombo
For i = 0 To .ListCount - 1
If StrComp(sText, Left$(.List(i), L), 1) = 0 Then
.ListIndex = i
.Text = .List(.ListIndex)
.SelStart = L
.SelLength = Len(.Text) - .SelStart
Exit For
End If
Next
End With
End If
End Sub

*** espero que te sirva ***

Un saludo.
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