954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Removing String from ListBox and From File .txt

So im trying to do a simple system in my VB Express Edition 2008 and what it does is add some car models (example) to a list box and stores it in a .txt file for future use. But when the user clicks a delete button it should delete from both the listbox and the .txt. Any Ideas?

I have to use only the FileOpen(OpenMode.Append or OpenMode.Input/Output) functions. Please Help! Thanks

RgCz
Newbie Poster
3 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

Try this code,

....
 If ListBox1.SelectedIndex <> -1 Then
            ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
            System.IO.File.WriteAllLines("file.txt", ListBox1.Items.Cast(Of String)().ToArray())
 End If
....
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: