Really need help -.-

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
14 posts Page 2 of 2
Contributors
User avatar
NeedHelp
Member
Member
Posts: 42
Joined: Fri Feb 19, 2010 3:57 pm

Re: Really need help -.-
NeedHelp
Help?
mandai wrote:
Code: Select all
File.WriteAllText("selected.txt", ListBox1.SelectedItem.ToString())
File.WriteAllText("textbox.txt", TextBox1.Text)
?
Source?
User avatar
lesan101
Top Poster
Top Poster
Posts: 193
Joined: Tue Jun 29, 2010 8:10 am

Re: Really need help -.-
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 : ))
Image
User avatar
lesan101
Top Poster
Top Poster
Posts: 193
Joined: Tue Jun 29, 2010 8:10 am

Re: Really need help -.-
lesan101
NVM !!!!!!!!!!!!!! :evil: I STILL GET AN ERROR..

coders out there tyr it. and maybe you know what to do?
Image
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Really need help -.-
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
14 posts Page 2 of 2
Return to “Tutorial Requests”