在VS中获得Combobox值

时间:2016-05-20 16:39:28

标签: vb.net combobox

我正在使用Combobox和Label Text制作一个简单的定价计算器。 我的Combobox有2个项目:周末(30.000)和工作日(20.000)。乘数是数量。

因此,如果我在组合框中选择“Weekend(30.000)”并输入“2”到qty,结果将是30.000 * 2 = 60.000。

我尝试了这段代码,但无法正常工作。

我想知道如何从“Weekend(30.000)”到30000获取字符串的值?

Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged
        Try
            lblFinal.Text = cboPrice.SelectedItem * txtQty.Text 
           Catch ex As Exception    
        End Try
End Sub



Private Sub cboPrice_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPrice.SelectedIndexChanged
    Try
        If cboPrice.SelectedIndex = 1 Then
            cboPrice.SelectedItem = "30000"
        ElseIf cboPrice.SelectedIndex = 2 Then
            cboPrice.SelectedText = "40000"
        End If
    Catch ex As Exception

    End Try
End Sub

1 个答案:

答案 0 :(得分:0)

我再次尝试使用此代码并且它有效。 。

Dim price as integer

Private Sub txtQty_TextChanged(sender As Object, e As EventArgs) Handles txtQty.TextChanged

        Try

            lblFinal.Text = Price * CInt(txtQty.Text)

        Catch ex As Exception

        End Try
    End Sub



    Private Sub cboPrice_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPrice.SelectedIndexChanged

        Try
            If cboPrice.SelectedIndex = 0 Then
                Price = 30000
            Else
                Price = 40000
            End If
        Catch ex As Exception

        End Try
    End Sub