在组合框中选择和项目,如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
答案 0 :(得分: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
答案 1 :(得分: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..