Logi Gunaratnam Logi Gunaratnam - 1 year ago 76
Vb.net Question

when "Not complete" is selected from a listbox i want 0 to be entered into a textbox

I have a listbox with an item called "Not complete" I want 0 to be entered into a textbox when this is selected is that possible?

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

CoreUnit1Total = CoreUnit1CSComBx.SelectedItem * CoreUnit1TxtBx.Text
End If

Answer Source

There many ways to do this, however the case statement is probably the best and in the long run is much cleaner than using the 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

If you have any trouble let me know, as mentioned above there is more than one way to achieve what you are wanting to accomplish.
Happy Coding!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download