2013-03-01 99 views
1

在組合框中選擇和項目後,如iphone5,samsung s3,htc等。如果用戶選擇Iphone5,則所選項目的說明將添加到文本框中。組合框項目更改時無法更改文本

它似乎無法正常工作,因爲每次我選擇不同的項目時,它只顯示分配給iphone5的描述。

If cboBrand.Items.Contains("Iphone5") = True Then 

     TxtBox1.Text = "OS : iOS 6, upgradable to iOS 6.1, Chipset: Apple A6, CPU: Dual-core 1.2 GHz" 

    ElseIf cboBrand.Items.Contains("Sumsung s3") = True Then 

     TxtBox1.Text = "Os: Android OS, (Ice Cream Sandwich), upgradeable to 4.1.2 (Jelly Bean, CPU: Quad-core 1.4 GHz Cortex-A9)" 

    End If 

回答

1

這裏有一個小比這更好的例子,特別是如果你有更多的添加...使用的情況下語句,而不是和前手宣佈你的琴絃......

Private Sub cboBrand_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles cboBrand.SelectedIndexChanged 

    Dim strIphone5 As String = "OS : iOS 6, upgradable to iOS 6.1, Chipset: Apple A6, CPU: Dual-core 1.2 GHz" 
    Dim strSumPhone As String = "Os: Android OS, (Ice Cream Sandwich), upgradeable to 4.1.2 (Jelly Bean, CPU: Quad-core 1.4 GHz Cortex-A9)" 

    Select Case cboBrand.SelectedItem 

     Case "iphone5" 
      txtAddress.Text = strIphone5 
     Case "Sumsung s3" 
      TextBox1.Text = strSumPhone 

    End Select 

    End Sub 

現在,如果你複製並粘貼這一點,到本月底小號ub並將其添加到它的結尾如果它不存在...

Handles cboBrand.SelectedIndexChanged 'Sometimes when copied it looses its handlers.. 
+0

哇。這對我有很大的幫助。非常感謝先生。我學習了新技術。 – 2013-03-01 07:12:53

+0

您的歡迎,如果此作品請務必對答案進行投票。祝你好運! – Codexer 2013-03-01 07:13:54

+0

我無法投票多1,我需要15點聲望投票morethan。但是之後。我很高興你幫助我。非常感謝先生。 – 2013-03-01 07:25:37

1

這將工作......而唯一的原因,它始終顯示iPhone 5的是因爲你的組合框始終包含這一點,這意味着它總是真的...

Private Sub cboBrand_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles cboBrand.SelectedIndexChanged 

    If cboBrand.SelectedItem = ("Iphone5") Then 

     txtAddress.Text = "OS : iOS 6, upgradable to iOS 6.1, Chipset: Apple A6, CPU: Dual-core 1.2 GHz" 

    ElseIf cboBrand.SelectedItem = ("Sumsung s3") Then 

     TextBox1.Text = "Os: Android OS, (Ice Cream Sandwich), upgradeable to 4.1.2 (Jelly Bean, CPU: Quad-core 1.4 GHz Cortex-A9)" 

    End If 
    End Sub 
+0

謝謝先生。有用。 – 2013-03-01 06:45:12

+0

歡迎您,我知道它會:) – Codexer 2013-03-01 06:45:38

+0

Theres另一種方式,你也可以做到這一點...只需一秒鐘,我認爲這是好多了,因爲你可以有很多elseif語句...... – Codexer 2013-03-01 06:46:57