Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a listbox and the user is able to add items to it using a textbox, so i wanna be able to save that list to a .dat file, im just not sure how to get it to loop until all items are saved.. i can do it with individual textboxes and things like that..

 

Here is the code I wanna use, just need to make it save everything in the list:

       Dim swMisc As System.IO.StreamWriter = _
New System.IO.StreamWriter(Application.StartupPath & "\Settings\listboxitems.dat", False)
       swMisc.WriteLine(Me.checkedlistbox1.Text)
       swMisc.Flush()
       swMisc.Close()
       swMisc = Nothing

 

also, is it possible to save if the user checked the item in the listbox (cuz im using a checked listbox)

Posted

It is giving me an error:

 

The application for project 'C:\SaveListtoFile\SaveListtoFile.csproj' is not installed.

Make sure the application for the project type (.csproj) is installed.

 

 

I ran the application in the debug folder and it works just how I need it to.. just can't see the code.

 

Thanks

Posted

I tried that, i also tried adding that form to an existing project.. but still can't get it to work.. could it be that i only have visual basic.net standard edition?

 

Could you just post the code that you have under the two save buttons?

Posted

ok, thanks for the opening in notepad idea.. so now I translated it to vb.net and i found the part that saves the items in a checkedlistbox which is:

        Dim fs As New System.IO.FileStream("list.dat", System.IO.FileMode.Create)
        Dim sw As New System.IO.StreamWriter(fs)
        Dim obj As Object
        For Each obj In  checkedListBox1.Items
           sw.WriteLine(obj.ToString())
        Next obj
        sw.Close()

Now, what would be the code to load the items in the .dat file into the checkedlistbox?

 

Thanks Diesel

Posted

checkedListBox1.Clear()

Dim fs As New System.IO.FileStream("list.dat", System.IO.FileMode.Create)
Dim sr As New System.IO.StreamReader(fs)
Dim obj As Object

While (sr.Read())
checkedListBox1.Items.Add(sr.ToString())
End While

sr.Close()
[/Code]

Posted

the saving the items in the listbox works perfectly but when I put the code in my load event to load the items into the textbox, my program for some reason won't even open.. i have to press the stop button because I can't even see the form.

 

heres the load code to get the items from the .dat file:

       Dim Miscfs As New System.IO.FileStream(Application.StartupPath & "MiscGoals.dat", System.IO.FileMode.Create)
       Dim Miscsr As New System.IO.StreamReader(Miscfs)
       Dim obj As Object
       While (Miscsr.Read())
           listboxMiscGoals.Items.Add(Miscsr.ToString())
       End While
       Miscsr.Close()

Posted

i changed it to FileMode.Open and it still won't even load the form.. can't see anything

 

EDIT:

I just removed this section of code from the code to load the items:

       While (Miscsr.Read())
           listboxMiscGoals.Items.Add(Miscsr.ToString())
       End While

Now the form will display when I run the program.. but of course it isn't loading the items since that is the part that does it. So I think that something is wrong with that section of the code.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...