0

hey there

i'm new in programing and there is a lot of hard things on me

:(

i want to make a program that take a value of text box and add it to the list box and one button to delete the selected item

i make that and this is my code

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles adbut.Click
        ListBox1.Items.Add(TextBox1.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delbut.Click

        ListBox1.SelectedItem.Clear()


    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

the problem that if the user didn't select an item and press the delete button the program will crush how can i make the button disable until user select item ?

i try this code but there is error :

If ListBox1.SelectedItem = True Then delbut.Enabled = True
        else
        delbut.Enabled = False
        ListBox1.SelectedItem.Clear()
end if

can you plz help ari ??

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by GeekByChoiCe
0
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If ListBox1.SelectedIndex < 0 Then
            Return
        End If
        ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
    End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.