更改组合框的默认值

时间:2014-05-09 11:56:19

标签: vb.net visual-studio-2012 combobox

所以我正在尝试创建一个基于菜单选项创建订单的应用程序。菜单使用组合框,然后我使用组合框选项添加总数的数字。但是,组合框的默认值为空,我希望它为“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 个答案:

答案 0 :(得分:1)

在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
相关问题