filtro en un objeto de vb
¿como puedo crear un filtro en un combo box? es decir para q al momento de escribir la primer letra de una palabra en el combo me vaya trayendo todas las palabras q empiezen con esa letra q escribi o conforme a lo qu vaya escribiendo. si alguien sabe que comando debo usar diganmelo por favor se los agradecere
Esto debes crear un combo y dentro del formulario copias esto tal y como esta, los campos q debes cambiar son los de Los nombres de la personas, adecuandolo a los datos q tu necesites filtrar, saludos y espero q te sirva ;)
Dim Combo1Borrado As Boolean
Private Sub Combo1_Change()
Static YaEstoy As Boolean
On Local Error Resume Next
If Not YaEstoy Then
YaEstoy = True
unCombo_Change Combo1.Text, Combo1
YaEstoy = False
End If
Err = 0
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
unCombo_KeyDown KeyCode
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
unCombo_KeyPress KeyAscii
End Sub
Private Sub unCombo_KeyDown(KeyCode As Integer)
If KeyCode = vbKeyDelete Then
Combo1Borrado = True
Else
Combo1Borrado = False
End If
End Sub
Private 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
Private 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
Private Sub Form_Load()
Combo1.AddItem "Carlos"
Combo1.AddItem "Jorge"
Combo1.AddItem "Miguel"
Combo1.AddItem "Javier"
Combo1.AddItem "Marta"
Combo1.AddItem "Pedro"
Combo1.AddItem "Abel"
Combo1.AddItem "Fernando"
Combo1.AddItem "Rafa"
Combo1.AddItem "Jose carlos"
End Sub
Dim Combo1Borrado As Boolean
Private Sub Combo1_Change()
Static YaEstoy As Boolean
On Local Error Resume Next
If Not YaEstoy Then
YaEstoy = True
unCombo_Change Combo1.Text, Combo1
YaEstoy = False
End If
Err = 0
End Sub
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
unCombo_KeyDown KeyCode
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
unCombo_KeyPress KeyAscii
End Sub
Private Sub unCombo_KeyDown(KeyCode As Integer)
If KeyCode = vbKeyDelete Then
Combo1Borrado = True
Else
Combo1Borrado = False
End If
End Sub
Private 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
Private 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
Private Sub Form_Load()
Combo1.AddItem "Carlos"
Combo1.AddItem "Jorge"
Combo1.AddItem "Miguel"
Combo1.AddItem "Javier"
Combo1.AddItem "Marta"
Combo1.AddItem "Pedro"
Combo1.AddItem "Abel"
Combo1.AddItem "Fernando"
Combo1.AddItem "Rafa"
Combo1.AddItem "Jose carlos"
End Sub
Hola, prueba con algo así, pero tendrás que depurarlo...
Private Sub Combo1_Change()
Dim tamaño As Integer
Dim i As Integer
tamaño = Len(Combo1.Text)
For i = 0 To Combo1.ListCount - 1
If Left(Combo1.Text, tamaño) = Left(Combo1.List(i), tamaño) Then
Combo1.Text = Combo1.List(i)
Exit For
End If
Next i
End Sub
Private Sub Form_Load()
Combo1.AddItem "antonio"
Combo1.AddItem "Pepe"
Combo1.AddItem "sergio"
Combo1.AddItem "manolo"
End Sub
Saludos
sdemingo
Private Sub Combo1_Change()
Dim tamaño As Integer
Dim i As Integer
tamaño = Len(Combo1.Text)
For i = 0 To Combo1.ListCount - 1
If Left(Combo1.Text, tamaño) = Left(Combo1.List(i), tamaño) Then
Combo1.Text = Combo1.List(i)
Exit For
End If
Next i
End Sub
Private Sub Form_Load()
Combo1.AddItem "antonio"
Combo1.AddItem "Pepe"
Combo1.AddItem "sergio"
Combo1.AddItem "manolo"
End Sub
Saludos
sdemingo