Visual Basic - vincular un textbox con un combobox

Life is soft - evento anual de software empresarial
 
Vista:

vincular un textbox con un combobox

Publicado por Fernando (29 intervenciones) el 17/11/2003 00:18:27
He combinadoun textbox y un combobox con este codigo. Hay otra forma de hacerlo mejor.
En el Textbox solo voy a introducir numeros de 4 cifras y en el combobox me devuelve texto.

Private Sub ComboBox1_Change()
If ComboBox1.ListIndex = 0 Then
TextBox1 = \"2048\"
End If
If ComboBox1.ListIndex = 1 Then
TextBox1 = \"0043\"
End If
If TextBox1 = \"0085\" Then
ComboBox1.ListIndex = 2
End If
If TextBox1 = \"0182\" Then
ComboBox1.ListIndex = 3
End If

End Sub

Private Sub TextBox1_Change()
If TextBox1 = \"2048\" Then
ComboBox1.ListIndex = 0
End If
If TextBox1 = \"0043\" Then
ComboBox1.ListIndex = 1
End If
If TextBox1 = \"0085\" Then
ComboBox1.ListIndex = 2
End If
If TextBox1 = \"0182\" Then
ComboBox1.ListIndex = 3
End If

End Sub

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:vincular un textbox con un combobox

Publicado por Ángel (42 intervenciones) el 17/11/2003 10:23:21
Te mando un ejemplo bastante simple en el que puedes hacer lo que deseas. Espero que te valga.

Private Sub Form_Load()
' Cargamos los elementos
txtDato = ""
With cmbLista
.AddItem "Uno"
.ItemData(.NewIndex) = 1
.AddItem "Dos"
.ItemData(.NewIndex) = 2
.AddItem "Tres"
.ItemData(.NewIndex) = 3
.AddItem "Cuatro"
.ItemData(.NewIndex) = 4
.AddItem "Cinco"
.ItemData(.NewIndex) = 5
.AddItem "Seis"
.ItemData(.NewIndex) = 6
.AddItem "Siete"
.ItemData(.NewIndex) = 7
.AddItem "Ocho"
.ItemData(.NewIndex) = 8
.AddItem "Nueve"
.ItemData(.NewIndex) = 9
.AddItem "Diez"
.ItemData(.NewIndex) = 10
.ListIndex = 0
End With
End Sub

Private Sub txtDato_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then SendKeys "{TAB}"
End Sub

Private Sub txtDato_LostFocus()
If CInt(txtDato) - 1 > cmbLista.ListCount Then ' Comprobamos que existe el elemento. Esto depende de los valores con los que se van a trabajar.
MsgBox "Elemento no encontrado"
txtDato.SetFocus
Else
cmbLista.ListIndex = CInt(txtDato) - 1 ' Seleccionamos el elemento adecuado.
End If
End Sub

Suerte.
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