Question need help creating a delete button with code below

cabalsdemon

New member
Joined
May 11, 2013
Messages
2
Programming Experience
3-5
i am a beginner at vb trying to populate a listbox then when i need to delete the selected file from list box it wont work please help thanks

i am using this code

VB.NET:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click        OpenFileDialog1.ShowDialog()
        TextBox1.Text = OpenFileDialog1.FileName
        BindingSource1.Add(OpenFileDialog1.FileName)
        ListBox1.Select()


       End Sub
and i am trying to figure out how to make a remove selected code with the data that code brings in
and every code that i try it always give this error

Items collection cannot be modified when the DataSource property is set
 
i am a beginner at vb trying to populate a listbox then when i need to delete the selected file from list box it wont work please help thanks

i am using this code

VB.NET:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click        OpenFileDialog1.ShowDialog()
        TextBox1.Text = OpenFileDialog1.FileName
        BindingSource1.Add(OpenFileDialog1.FileName)
        ListBox1.Select()


       End Sub
and i am trying to figure out how to make a remove selected code with the data that code brings in
and every code that i try it always give this error

well sorry for that i figured it out when i looked at the code better

for anyone who would like to know the cure for a delete button for this code is

VB.NET:
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click        Dim m_index As Integer
        m_index = ListBox1.SelectedIndex
        BindingSource1.RemoveAt(m_index)




    End Sub
change the button8_Click to what your button is and it will work
 
Back
Top