【问题标题】:when "Not complete" is selected from a listbox i want 0 to be entered into a textbox当从列表框中选择“未完成”时,我希望将 0 输入到文本框中
【发布时间】:2016-05-04 18:53:37
【问题描述】:

我有一个列表框,其中包含一个名为“未完成”的项目,我希望在选择此项时将 0 输入到文本框中,这可能吗?

    If CoreUnit1ComboBx.SelectedItem = Nothing Or CoreUnit1CSComBx.SelectedItem = Nothing Or CoreUnit1TxtBx.Text = "" Then
    ElseIf CoreUnit1CSComBx.SelectedItem = "Not Complete" Then
        CoreUnit1Total = 0
        CoreUnit1TxtBx.Text = "0" 

    Else
        CoreUnit1Total = CoreUnit1CSComBx.SelectedItem * CoreUnit1TxtBx.Text
    End If

【问题讨论】:

  • 当前代码有什么问题?你有什么错误吗
  • 选择“未完成”后 0 没有出现在我的文本框中,我的老师说我必须使用一个按钮,但我希​​望 0 在选择后立即出现在文本框中
  • 你在哪里运行这段代码?它在 SelectedIndexChanged 事件处理程序中吗?顺便说一句,你的老师对将字符串与对象相乘没有什么可说的?

标签: vb.net textbox listbox selecteditem


【解决方案1】:

有很多方法可以做到这一点,但case statement 可能是最好的,从长远来看比使用if statement 更干净。

Public Class Form1
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    Select Case ComboBox1.SelectedItem
        Case Is = "Not Completed"
            TextBox1.Text = "0"
    End Select
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ComboBox1.Items.Add("Not Completed")
End Sub
End Class

如果您有任何问题,请告诉我,如上所述,实现您想要完成的目标的方法不止一种。
快乐编码!

【讨论】:

猜你喜欢
  • 2014-12-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-10
  • 1970-01-01
  • 2020-09-18
  • 1970-01-01
  • 1970-01-01
  • 2013-02-04
相关资源
最近更新 更多