Generate text from a combobox

Asked

Viewed 102 times

0

I’m creating a program: inserir a descrição da imagem aqui

I would like to know how to generate a code by selecting one of the combobox items. For example: I select the "Solved issue" item, in the textbox it would appear "Question marked as solved".

Thanks in advance.

2 answers

1

Private Sub Form_Load()
  Combo1.AddItem "Text1"
  Combo1.AddItem "Text2"
  Combo1.AddItem "Text3"
  Combo1.AddItem "Text4"
End Sub

Private Sub Combo1_Click() 'ListIndex inicia com 0 (zero) Dim strTeste As String Select Case Combo1.ListIndex Case 0 strTeste = "Text1" Case 1 strTeste = "Text2" Case 2 strTeste = "Text3" Case 3 strTeste = "Text4" End Select If Combo1.Text = strTeste Then MsgBox "OK!" End Sub

0


From what I understand you want to check when the selected in the Combo box exists in the options and create a message for this.

Private Sub ComboBox1_TextChanged(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged
        If ComboBox1.Items.Contains(Trim(ComboBox1.Text)) Then
            'Ação ocorre se o texto da Combo box conter nos itens da Combo box
            Dim m As String = ""
            Select Case ComboBox1.Text
                Case "Questão resolvida" 'texto da Combo box
                    m = "Questão marcada como resolvida" 'mensagem se a questão for resolvida
                Case "Questão anulada"
                    m = "Questão marcada como anulada" 'mensagem se a questão for anulada
            End Select
            TextBox1.Text = m
        Else
            TextBox1.Text = ""
        End If
    End Sub

Textbox1.text is the output of the text.

Combobox1 is the Combo Box.

  • Once again, thank you for your help!! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.