❗ How to make Text-box text load from listbox?

Posts 1–12 of 12 · Page 1 of 1
❗ How to make Text-box text load from listbox?
Hello,

I decided to make a diary, Which has:
-Richtextbox
-listbox
-button

imgur: the simple image sharer <- the app

Things I did:

-Created a mysettings entry which saves the text in the textbox to mysettings when i press the button
-shows an entry in the listbox after each save


My Problem:
-there is only one save slot, meaning it wont save different versions of the text (only the latest)


Help required:


How do I make it so saves to a specific listbox entry (for ex. day1's entry is saved as day 1 in the listbox, and can be loaded up again when that listitem is clicked)


please reply and thanks
Quote Originally Posted by hopefordope View Post
Hello,

I decided to make a diary, Which has:
-Richtextbox
-listbox
-button

imgur: the simple image sharerⓘ <- the app

Things I did:

-Created a mysettings entry which saves the text in the textbox to mysettings when i press the button
-shows an entry in the listbox after each save


My Problem:
-there is only one save slot, meaning it wont save different versions of the text (only the latest)


Help required:


How do I make it so saves to a specific listbox entry (for ex. day1's entry is saved as day 1 in the listbox, and can be loaded up again when that listitem is clicked)


please reply and thanks
Before I attempt to help you, I want to know exactly how you want things to work.
How do you want the text to be stored?
What event do you want to happen for the text to be stored?
How do you want the text to be saved?
Do you want everything in the textbox to be saved or just pieces?

Can't answer those? Answer this.
Do you want me to help you?
I'll help you get this program done for sure.

I was soo bored when I typed that.
Ok thank you very much for your help

-I wanted the text to be stored internally as part of the my.settings page

- In order this is what happens::: I write the stuff down in the textbox> Then I press the button> The button prompts me an input box which tells me to name the entry>After I name the entry is stored as a my.settings item> The name i entered is also added as an item in the listbox.

If i click an item in the listbox, the text associated with the specific listbox item is viewed on the textbox

-Yes, i want the whole text saved

I hope this clarifies things
(I just want a simple diary where the listbox is it's table of contents and the textbox is the diary pages)
Quote Originally Posted by hopefordope View Post
Ok thank you very much for your help

-I wanted the text to be stored internally as part of the my.settings page

- In order this is what happens::: I write the stuff down in the textbox> Then I press the button> The button prompts me an input box which tells me to name the entry>After I name the entry is stored as a my.settings item> The name i entered is also added as an item in the listbox.

If i click an item in the listbox, the text associated with the specific listbox item is viewed on the textbox

-Yes, i want the whole text saved

I hope this clarifies things
(I just want a simple diary where the listbox is it's table of contents and the textbox is the diary pages)
In your settings, create a list. Its named specializedstring.collection.. something like that.

Code:
Private seperator As String = " &|& "
    Private sTitle, sTime, sText As String
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If RichTextBox1.Text <> Nothing Then


            sTitle = InputBox("Prompt", "Title", "Default Response")
            sTime = Format(DateTime.Now, "h:m:s tt | MM/dd/yy")
            sText = RichTextBox1.Text
            My.Settings.Setting.Add(Text & seperator & sTitle & seperator & sTime)


            Dim item As New ListViewItem(sTitle)
            item.SubItems.Add(sTime)
            ListView1.Items.Add(item)


        End If
    End Sub


    Private Sub ListView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListView1.SelectedIndexChanged
        If RichTextBox1.Modified Then
            RichTextBox1.Text = GetString(0)
        End If
    End Sub


    Private Function GetString(ByVal Index As Integer) As String
        Dim newArray() As String = My.Settings.Setting.Item(ListView1.FocusedItem.Index).Split(seperator)
        Return newArray(Index)
    End Function


    Private Function LoadString(ByVal Index As Integer) As String
        Dim newArray() As String = My.Settings.Setting.Item(ListView1.FocusedItem.Index).Split(seperator)
        Return newArray(Index)
    End Function


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        If My.Settings.FirstTime = True Then
            My.Settings.FirstTime = False
        Else


            For Each i As String In My.Settings.Setting
                Dim newArray() As String = My.Settings.Setting.Item(i).Split(seperator)
                Dim item As New ListViewItem(newArray(1))
                item.SubItems.Add(newArray(2))
                ListView1.Items.Add(item)
            Next
        End If
    End Sub
Its pretty simple. You should be able to follow
Most likely have errors

or... using a text file..

Code:

Code:
Private fileLoc As String = Application.StartupPath & "\File.txt"
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim myWriter As New IO.StreamWriter(fileLoc, False)
        For Each myItem As ListViewItem In ListView1.Items
            myWriter.WriteLine(myItem.Text & "|" & myItem.SubItems(1).Text)
        Next
        myWriter.Close()


        Dim sReader As New StreamReader(Application.StartupPath & "\File.txt")
        Dim reader As String = sReader.ReadToEnd
       
        Dim sWriter As New StreamWriter(Application.StartupPath & "\File.txt")
        sWriter.Write(reader)
        sWriter.Close()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Form2.ShowDialog()
        If IO.File.Exists(fileLoc) Then
            Dim fileLocLines() As String = IO.File.ReadAllLines(fileLoc)
            For Each line As String In fileLocLines
                Dim lineArray() As String = line.Split("|")
                Dim newItem As New ListViewItem(lineArray(0))
                newItem.SubItems.Add(lineArray(1))
                ListView1.Items.Add(newItem)
            Next
        End If
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim i() As String
        i = TextBox1.Text.Split("|")
        Dim item As New ListViewItem(i(0))
        item.SubItems.Add(i(1))
        ListView1.Items.Add(item)
        TextBox1.Clear()
    End Sub
Hello, I was going to go with the my.settings method

the code had some errors but i was able to fix most of them, except for these:

1) [from button1.click]


My.Settings.Setting.Add(Text & seperator & sTitle & seperator & sTime)

"Setting" is not a member of My.Settings.
the farthest it ill go upto is My.Settings

same thing happens with
My.Settings.Setting.Item(ListView1.FocusedItem.Ind ex).Split(seperator)

2) [top of form1.load]


If My.Settings.FirstTime = True Then
My.Settings.FirstTime = False
Else


"FirstTime" is not a member of My.Settings
or it might not have been declared

Thanks for your help

also I am using Visual Studio 2012, i hope this hasn't been causing the errors
Quote Originally Posted by hopefordope View Post
Hello, I was going to go with the my.settings method

the code had some errors but i was able to fix most of them, except for these:

1) [from button1.clickⓘ]


My.Settings.Setting.Add(Text & seperator & sTitle & seperator & sTime)

"Setting" is not a member of My.Settings.
the farthest it ill go upto is My.Settings

same thing happens with
My.Settings.Setting.Item(ListView1.FocusedItem.Ind ex).Split(seperator)

2) [top of form1.load]


If My.Settings.FirstTime = True Then
My.Settings.FirstTime = False
Else


"FirstTime" is not a member of My.Settings
or it might not have been declared

Thanks for your help

also I am using Visual Studio 2012, i hope this hasn't been causing the errors
You have those errors because we have different name for those settings.
Such as Setting, it takes place of the sepcializedstringcollection and firsttime is a boolean value. I forgot to mention that.
Quote Originally Posted by DawgiiStylz View Post

You have those errors because we have different name for those settings.
Such as Setting, it takes place of the sepcializedstringcollection and firsttime is a boolean value. I forgot to mention that.

umm i am still quite confused.. do i replace setting with specialiedstringcollection ? or what do i do to make it work?


and i added FirstTime as a setting entry (Boolean/False) and now it works...
Quote Originally Posted by hopefordope View Post



umm i am still quite confused.. do i replace setting with specialiedstringcollection ? or what do i do to make it work?


and i added FirstTime as a setting entry (Boolean/False) and now it works...
Now do the same with the other.
Set the TYPE to specializedstring.collection
Set the name to anything you want.

[Its another setting in the settings.. What do you call those :l]
ok that fixed all the errors but now after i run it there is an error
This is what happend
>I run the app
>I write something in the textbox
>I hit the button
>it prompts me with the title name
>Then this happens after I press ok

imgur: the simple image sharer
Quote Originally Posted by hopefordope View Post
-I wanted the text to be stored internally as part of the my.settings page
You're aware of that the settings file is stored in the AppData folder. (Temp Files)

And won't be stored within the program itself.


My Tip:
XML, allows you to easy structure your work.

1 Parent for each 'listbox item'
And Childs/Nodes for the content under that item.
Here's some untested scratch code. Have fun using it:
Code:
' Global Shit:
Dim entries As New List(Of String)

'Sub
Sub SaveYoShit()
    Dim name As String = InputBox("What should the name of your entry be?")
    if name <> nothing then
         entries.items.add(textbox1.text)
         listbox1.items.add(name)
    else ' They pressed cancel or didn't enter anything
        ' Do Nothing
        ' The else doesn't need to be here, i just put it here incase you put more after the if. 
        'When you start to get hundreds of lines between an if and an else, it gets annoying having to remember what each else is for
     end if
End Sub

' Sub
Sub RecallYoShit() Handles MyListBo*****lectedIndexChanged
     if MyListBo*****lectedIndex >= 0 Then
         textbox1.text = entries(MyListBo*****lectedIndex)
     end if
End Sub
Good day

or are we trying to load at start up?
Quote Originally Posted by hopefordope View Post
"FirstTime" is not a member of My.Settings
or it might not have been declared
Did you create the setting?
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us