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
4

2 回答 2

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
于 2013-03-01T06:03:08.277 回答
1

这是一个比这更好的例子,特别是如果您要添加更多内容...请改用 case 语句并事先声明您的字符串...

  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

现在,如果您复制并粘贴此内容,请转到此子项的末尾,如果不存在则将其添加到其末尾...

 Handles cboBrand.SelectedIndexChanged 'Sometimes when copied it looses its handlers..
于 2013-03-01T06:58:55.480 回答