2014-05-20 43 views
0

我有5個不同的選項組合框中選擇的項目如何顯示隱藏的文本框,「一名球員」,「兩名球員」,「三名球員」等我的要求是,當用戶選擇的東西從組合框中可以看到等價的文本框,即如果選擇了「單個玩家」,則應出現一個文本框,以便用戶輸入該值。兩個和三個一樣。請建議。當在組合框中

回答

1

enter image description here

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged 
    If ComboBox1.Text.Trim.Contains("Player 1") = True Then 
     TextBox1.Visible = True 
     TextBox2.Visible = False 
     TextBox3.Visible = False 
    ElseIf ComboBox1.Text.Trim.Contains("Player 2") = True Then 
     TextBox1.Visible = True 
     TextBox2.Visible = True 
     TextBox3.Visible = False 
    ElseIf ComboBox1.Text.Trim.Contains("Player 3") = True Then 
     TextBox1.Visible = True 
     TextBox2.Visible = True 
     TextBox3.Visible = True 
    End If 
End Sub 
0

嘗試是這樣的:

Sub cbC(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged 
    Select Case ComboBox1.SelectedIndex 
     Case 0 
      TextBox1.Visible = False 
      TextBox2.Visible = False 
     Case 1 
      TextBox1.Visible = True 
      TextBox2.Visible = False 
     Case 2 
      TextBox1.Visible = True 
      TextBox2.Visible = True 
    End Select 
End Sub 

或者,根據什麼更好的適合你的需求:

Sub cbC(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged 
    TextBox1.Visible = (ComboBox1.SelectedIndex = 0) 
    TextBox1.Visible = (ComboBox1.SelectedIndex = 1) 
End Sub 
-1

TextBox1.Visible = (ComboBox1.SelectedIndex = 0)完美。

您還必須確保屬性下設置可見爲False您的文本框和標籤。否則,當您運行應用程序時,您的文本框將最初可見。