locked
save text in textboxes RRS feed

  • Question

  • I want to save text in the textboxes using a save button BUT i don't want to save it to any files just in the textboxes until its changed by the user and saved again so that everytime the application is executed the text will still be there. would this be a property of the textbox or is it even possible to do this.  I really don't want to use a database or lists or files just the same text in the textbox after the savebutton is clicked.  thank you so much.
    Friday, August 10, 2007 5:29 AM

Answers

  • The following will work:

    1. Add TextBox1 to your form

    2. Right-click on your application and go to Properties

    3. Make sure Enable Application Framework is checked

    4. Check Save My.Settings on Shutdown

    5. Click the Settings tab

    6. Add a new Setting named 'SavedText', set the type to String and the scope to User

    7. Add the following code to the Form.Load handler:

        TextBox1.DataBindings.Add("text", My.Settings, "SavedText")


    Friday, August 10, 2007 6:19 AM
  • Hi Bra49er,

     

                       Try to use Settings....under application properties-> Settings-> Value (try to add what do you want)

     

    To Load the Setting in textbox

     

    Textbox1.text = My.Settings.Nameofyourstring

     

    To Change the Value

     

    My.Settings.Nameofyourstring = Textbox1.text

    My.Settings.Save

     

     

    Regards

     

     

                   

     

    Friday, August 10, 2007 6:30 AM
  • To save

    My.Settings.Nameofyourstring = Textbox1.text

    My.Settings.Save

     

    Friday, August 10, 2007 6:40 AM
  • The settings are save automatically if My.SaveSettings on Shutdown is checked otherwise you can call My.Settings.Save manually with you save button.
    Friday, August 10, 2007 6:44 AM
  • ok why don't you try something different

    make sure that you have the correct name of the setting in your code

    the setting name below in bold needs to be your setting name

     

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

    TextBox1.text = My.Settings.Textsaved

    End Sub


        Private Sub button_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_save.Click
           
            My.Settings.textsaved = TextBox1.Text
            My.Settings.Save()


        End Sub

         

     

    Tuesday, August 14, 2007 6:35 PM
  • to make this easy on you

    you should make a setting location for each item you want to save

    then you would use seperate code for each one

     

    let's say you have 2 textboxes - you want to save the text from each one so you can recall the text when you run again

     

    create a setting for each one

    then refer to them just like above

     

    save button click event

    my.settings.textbox1settingname = me.textbox1.text

    my.settings.textbox2settingname = me.textbox2.text

     

    then you can call the text when the form loads

    just use the same code above but change it to match your setting names

    form load event

    me.textbox1.text = my.settings.textbox1settingname

    etc...

    Tuesday, August 14, 2007 8:32 PM

All replies

  • The following will work:

    1. Add TextBox1 to your form

    2. Right-click on your application and go to Properties

    3. Make sure Enable Application Framework is checked

    4. Check Save My.Settings on Shutdown

    5. Click the Settings tab

    6. Add a new Setting named 'SavedText', set the type to String and the scope to User

    7. Add the following code to the Form.Load handler:

        TextBox1.DataBindings.Add("text", My.Settings, "SavedText")


    Friday, August 10, 2007 6:19 AM
  • Hi Bra49er,

     

                       Try to use Settings....under application properties-> Settings-> Value (try to add what do you want)

     

    To Load the Setting in textbox

     

    Textbox1.text = My.Settings.Nameofyourstring

     

    To Change the Value

     

    My.Settings.Nameofyourstring = Textbox1.text

    My.Settings.Save

     

     

    Regards

     

     

                   

     

    Friday, August 10, 2007 6:30 AM
  •  ssta wrote:

    The following will work:

    1. Add TextBox1 to your form

    2. Right-click on your application and go to Properties

    3. Make sure Enable Application Framework is checked

    4. Check Save My.Settings on Shutdown

    5. Click the Settings tab

    6. Add a new Setting named 'SavedText', set the type to String and the scope to User

    7. Add the following code to the Form.Load handler:

        TextBox1.DataBindings.Add("text", My.Settings, "SavedText")



    how do i make work with the savebutton?
    Friday, August 10, 2007 6:38 AM
  • To save

    My.Settings.Nameofyourstring = Textbox1.text

    My.Settings.Save

     

    Friday, August 10, 2007 6:40 AM
  • The settings are save automatically if My.SaveSettings on Shutdown is checked otherwise you can call My.Settings.Save manually with you save button.
    Friday, August 10, 2007 6:44 AM
  • ok so this is what i did but i want only the save button to save it and this code made it save and stay saved without the button. Did  i do something wrong?


        Private Sub IncomeForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            TextBox1.DataBindings.Add("text", My.Settings, "Textsaved")

        End Sub


        Private Sub button_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_save.Click
           
            My.Settings.textsaved = TextBox1.Text
            My.Settings.Save()
        End Sub
       Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

           My.Settings.textsaved = TextBox1.Text

            My.Settings.Save()
           
     End Sub

    Tuesday, August 14, 2007 3:18 AM
  • the databinding code is binding your textbox to your setting location

    it will save the text automatically when you close the app if you have save my.settings on shutdown checked in your project properties (uncheck this if you want to save only with the save button)

     

    the textchanged event will update and save your setting every time you type something in the box

    Remove this code completely if you only want to save with the save button

    Tuesday, August 14, 2007 3:47 AM
  • ok so i unchecked the databinding code and removed the textchanged event code completely.  my save button is still not saving the text with the code that I have in it. am i missing something?
    Tuesday, August 14, 2007 6:08 PM
  • ok why don't you try something different

    make sure that you have the correct name of the setting in your code

    the setting name below in bold needs to be your setting name

     

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

    TextBox1.text = My.Settings.Textsaved

    End Sub


        Private Sub button_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_save.Click
           
            My.Settings.textsaved = TextBox1.Text
            My.Settings.Save()


        End Sub

         

     

    Tuesday, August 14, 2007 6:35 PM
  • ok that worked, so if i want more things on the form to save with that button like other textboxes and comboboxes and datetimepickers do i just substitute textbox1.text with combobox1.text or does a different word go there? or is there an easier way to list them or just use one word or phrase to make them all save? thank you for being so patient with me Smile
    Tuesday, August 14, 2007 7:06 PM
  • to make this easy on you

    you should make a setting location for each item you want to save

    then you would use seperate code for each one

     

    let's say you have 2 textboxes - you want to save the text from each one so you can recall the text when you run again

     

    create a setting for each one

    then refer to them just like above

     

    save button click event

    my.settings.textbox1settingname = me.textbox1.text

    my.settings.textbox2settingname = me.textbox2.text

     

    then you can call the text when the form loads

    just use the same code above but change it to match your setting names

    form load event

    me.textbox1.text = my.settings.textbox1settingname

    etc...

    Tuesday, August 14, 2007 8:32 PM
  • So now I am trying to make it so that when the exit button is clicked that the user will be asked (only if data has been changed and not saved) if they want to save their data before exiting.  I have found code and examples but those only seem to work with saving data in databases and not using my.settings to save.  Is there a way to do this with my.settings or another way to save data without using my.settings to keep the data in the boxes everytime the user opens the program. I hope I made sense here.  I would post some of my code but its a complete mess right now and I'm wondering if there is an easier way to do this.
    Monday, April 28, 2008 5:36 AM
  •  Bra49er wrote:
    So now I am trying to make it so that when the exit button is clicked that the user will be asked (only if data has been changed and not saved) if they want to save their data before exiting.  I have found code and examples but those only seem to work with saving data in databases and not using my.settings to save.  Is there a way to do this with my.settings or another way to save data without using my.settings to keep the data in the boxes everytime the user opens the program. I hope I made sense here.  I would post some of my code but its a complete mess right now and I'm wondering if there is an easier way to do this.

    I'm sorry I realize that I have already asked this question on another thread. Sorry about that.
    Monday, April 28, 2008 7:27 AM