Page 2 of 2

Re: Really need help -.-

Posted: Sat Jul 24, 2010 3:27 pm
by NeedHelp
Help?
mandai wrote:
Code: Select all
File.WriteAllText("selected.txt", ListBox1.SelectedItem.ToString())
File.WriteAllText("textbox.txt", TextBox1.Text)
?
Source?

Re: Really need help -.-

Posted: Sat Jul 24, 2010 6:23 pm
by lesan101
Yo after years of googling.. i found the solution
it helped me.. so it should help you!

if you have a save button. DELETE IT!
you dont need it.
THIS IS FOR LISTBOX SAVING.


okay on form_load add this:
Code: Select all
'ontop of private sub add this:

Private Const APP_NAME As String = "SaveRestoreListBox"
    Private Const SECTION_NAME As String = "Items"

'then under private sub:

Dim i As Integer = 0
        Do
            Dim new_value As String = GetSetting(APP_NAME, _
                SECTION_NAME, "Item" & i.ToString())
            If new_value.Length = 0 Then Exit Do

            ListBox1.Items.Add(new_value)
            
            i += 1
        Loop
Then add this code on form_close:
Code: Select all
For i As Integer = 0 To ListBox1.Items.Count - 1
            SaveSetting(APP_NAME, SECTION_NAME, "Item" & _
                i.ToString(), ListBox1.Items(i).ToString())
            SaveSetting(APP_NAME, SECTION_NAME, "Item" & _
                i.ToString(), ListBox2.Items(i).ToString())
            SaveSetting(APP_NAME, SECTION_NAME, "Item" & _
                i.ToString(), ListBox3.Items(i).ToString())
        Next i
THERE YOUR DONE!~
IF YOU ADD A ME.CLOSE CODE then your ganna get an error when pressing it
so if you wanna close it just press the form 'X" button on top : )

+Rep me if it helped : ))

Re: Really need help -.-

Posted: Sat Jul 24, 2010 6:26 pm
by lesan101
NVM !!!!!!!!!!!!!! :evil: I STILL GET AN ERROR..

coders out there tyr it. and maybe you know what to do?

Re: Really need help -.-

Posted: Sat Jul 24, 2010 8:06 pm
by mandai
What are we trying to do? Save/load some listbox items?
Code: Select all
    Dim lines As List(Of String)

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

        ListBox1.Items.Clear()
        Dim lines_a As String() = File.ReadAllLines("lines.txt")
        lines = New List(Of String)(lines_a)

        For i As Integer = 0 To lines.Count - 1
            ListBox1.Items.Add(lines(i))
        Next
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        lines.Add("new item")
        File.WriteAllLines("lines.txt", lines.ToArray())
        Form1_Load(Nothing, Nothing)
    End Sub

    Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
        lines.RemoveAt(ListBox1.SelectedIndex)
        File.WriteAllLines("lines.txt", lines.ToArray())
        Form1_Load(Nothing, Nothing)
    End Sub