Results 1 to 7 of 7

Thread: [RESOLVED] Save to setting status of control

  1. #1

    Thread Starter
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Resolved [RESOLVED] Save to setting status of control

    I want to save status of control

    example : enable or not properties of control.

    what type of setting have i to modify ?
    --***----------***-----

    If i help you please rate me.

    Working with Excel * Working with String * Working with Database * Working with array *

    K51 ĐH BÁCH KHOA HÀ NỘI - Khoa CNTT pro.

  2. #2
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Save to setting status of control

    One way to save the settings would be to use My.Settings.

    But you can also try PropertyBinding which requires no code. You just have to click on the control, click on the + by ApplicationSettings, Click on PropertyBinding so that the ... button appears, click it, find the setting you want, click the drop down box for it, select new and create a variable, then select that variable in the drop down box.

    It sounds long but it's really not that complicated. After you do that the property will save and load on its own.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  3. #3

    Thread Starter
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: Save to setting status of control

    Quote Originally Posted by Vectris View Post
    One way to save the settings would be to use My.Settings.

    But you can also try PropertyBinding which requires no code. You just have to click on the control, click on the + by ApplicationSettings, Click on PropertyBinding so that the ... button appears, click it, find the setting you want, click the drop down box for it, select new and create a variable, then select that variable in the drop down box.

    It sounds long but it's really not that complicated. After you do that the property will save and load on its own.
    Very great!!! As far as i didnt notify it. thanks. i ll rate you.

    have you read my PM ?
    --***----------***-----

    If i help you please rate me.

    Working with Excel * Working with String * Working with Database * Working with array *

    K51 ĐH BÁCH KHOA HÀ NỘI - Khoa CNTT pro.

  4. #4

    Thread Starter
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: Save to setting status of control

    But i want to save item of listbox to application setting.

    i dont see items properties of listbox.

    i did that with save setting but i want in application setting.

    how can i do that.
    --***----------***-----

    If i help you please rate me.

    Working with Excel * Working with String * Working with Database * Working with array *

    K51 ĐH BÁCH KHOA HÀ NỘI - Khoa CNTT pro.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Save to setting status of control

    To get one thing clear to begin with, there's only one Settings. When you bind application settings in the designer you're using the same setting as you would be if you used My.Settings in code.

    Now, as far as saving the contents of a ListBox, I would suggest that you use a StringCollection in your Settings. You can bind that directly to your ListBox in code if you want. That said, if the list is changing then I'd suggest that you create BindingList from the StringCollection first, then bind the BindingList to the ListBox. You can then add, edit and remove items in the list and, at shutdown, copy the list contents of the BindingList back to the StringCollection for saving. There's no need for you to explicitly save the StringCollection because it will be saved automatically at shutdown, along with all your other settings.
    vb.net Code:
    1. Imports System.ComponentModel
    2. Imports System.Collections.Specialized
    3.  
    4. Public Class Form1
    5.  
    6.     Private listItems As New BindingList(Of String)
    7.  
    8.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    9.         'Create the settings collection on the first run.
    10.         If My.Settings.ListItems Is Nothing Then
    11.             My.Settings.ListItems = New StringCollection
    12.         End If
    13.  
    14.         'Load the data from the settings.
    15.         For Each listItem As String In My.Settings.ListItems
    16.             Me.listItems.Add(listItem)
    17.         Next
    18.  
    19.         'Display the data.
    20.         Me.ListBox1.DataSource = Me.listItems
    21.     End Sub
    22.  
    23.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    24.         'Add a new item.
    25.         Me.listItems.Add(Me.TextBox1.Text)
    26.         Me.listItems.ResetItem(Me.listItems.Count - 1)
    27.     End Sub
    28.  
    29.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    30.         If Me.ListBox1.SelectedItem IsNot Nothing Then
    31.             'Edit the current item.
    32.             Me.listItems(Me.ListBox1.SelectedIndex) = Me.TextBox1.Text
    33.             Me.listItems.ResetItem(Me.ListBox1.SelectedIndex)
    34.         End If
    35.     End Sub
    36.  
    37.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    38.         If Me.ListBox1.SelectedItem IsNot Nothing Then
    39.             'Delete the current item.
    40.             Me.listItems.RemoveAt(Me.ListBox1.SelectedIndex)
    41.             Me.listItems.ResetItem(Me.ListBox1.SelectedIndex)
    42.         End If
    43.     End Sub
    44.  
    45.     Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
    46.         'Clear the old data.
    47.         My.Settings.ListItems.Clear()
    48.  
    49.         'Save the current data.
    50.         For Each listItem As String In Me.listItems
    51.             My.Settings.ListItems.Add(listItem)
    52.         Next
    53.     End Sub
    54.  
    55. End Class
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    Re: Save to setting status of control

    I don't think you can property bind a ListBox's Items.

    Instead you'll have to use My.Settings. To do that go to your Application Properties > Settings Tab and create a new settings. You might want an arraylist of whatever datatype you have in your listbox. Then to save it on form close

    Code:
    My.Settings.ARRAYLIST = ListBox.Items
    However you may have to use .AddRange or just loop through the items and add them to the array, I'm not really sure. But that is how you would reference My.Settings. And then on Form Load event you would do the same thing in reverse.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  7. #7

    Thread Starter
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: Save to setting status of control

    Thanks for all your helps. i am appreciative your helps.

    Hope you read my PM for you.

    I am doing a project . we are limited about time. (2 months for it)
    Last edited by manhit45; Jun 27th, 2009 at 10:55 PM.
    --***----------***-----

    If i help you please rate me.

    Working with Excel * Working with String * Working with Database * Working with array *

    K51 ĐH BÁCH KHOA HÀ NỘI - Khoa CNTT pro.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width