So I'm trying to make an App that creates an order based on menu choices. The menu uses combo boxes and then I use the combo box choice to add the numbers for the total. However, the default value of the combo boxes is blank, and I'd like it to be '0'. How do I change the selected Index to 0 instead of minus one without overwriting the choice of the user. My code:
所以我正在尝试创建一个基于菜单选项创建订单的应用程序。菜单使用组合框,然后我使用组合框选项添加总数的数字。但是,组合框的默认值为空,我希望它为“0”。如何在不覆盖用户选择的情况下将所选索引更改为0而不是减1。我的代码:
Public Class addOrder
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim A = Convert.ToInt32(margQty.Text) * 9.5
Dim B = Convert.ToInt32(hawQty.Text) * 10.5
Dim C = Convert.ToInt32(pepQty.Text) * 10.5
Dim D = Convert.ToInt32(pepDelQty.Text) * 11.5
Dim E1 = Convert.ToInt32(pineQty.Text) * 0.5
Dim F = Convert.ToInt32(hamQty.Text) * 0.5
Dim G = Convert.ToInt32(cheQty.Text) * 1.0
Dim H = Convert.ToInt32(exPepQty.Text) * 0.5
Dim SubTot As Double = (A + B + C + D + E1 + F + G + H)
Dim Tot As String = (SubTot) * 1.2
MsgBox("The order sub total total is: £" + Str(SubTot) & vbCrLf & "The order total is £" + Tot)
End Sub
End Class
1 个解决方案
#1
1
During your Form Load event (double-click the form in the IDE), populate your combo box, then use this to set the default index:
在Form Load事件期间(双击IDE中的表单),填充组合框,然后使用它来设置默认索引:
e.g.:
例如。:
Private Sub frmName_Load(ByVal sender As Object, ByVal e As System.EventArgs) Me.Load
'Load/call whatever you'd like for this particular form
'...
'Populate your combo box through a list or manually
'...
'Set the default selected index:
If YourComboBox.Items.Count > 0
YourComboBox.SelectedIndex = 0
End Sub
#1
1
During your Form Load event (double-click the form in the IDE), populate your combo box, then use this to set the default index:
在Form Load事件期间(双击IDE中的表单),填充组合框,然后使用它来设置默认索引:
e.g.:
例如。:
Private Sub frmName_Load(ByVal sender As Object, ByVal e As System.EventArgs) Me.Load
'Load/call whatever you'd like for this particular form
'...
'Populate your combo box through a list or manually
'...
'Set the default selected index:
If YourComboBox.Items.Count > 0
YourComboBox.SelectedIndex = 0
End Sub