I want to save status of control
example : enable or not properties of control.
what type of setting have i to modify ?
Printable View
I want to save status of control
example : enable or not properties of control.
what type of setting have i to modify ?
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.
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.
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:
Imports System.ComponentModel Imports System.Collections.Specialized Public Class Form1 Private listItems As New BindingList(Of String) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Create the settings collection on the first run. If My.Settings.ListItems Is Nothing Then My.Settings.ListItems = New StringCollection End If 'Load the data from the settings. For Each listItem As String In My.Settings.ListItems Me.listItems.Add(listItem) Next 'Display the data. Me.ListBox1.DataSource = Me.listItems End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Add a new item. Me.listItems.Add(Me.TextBox1.Text) Me.listItems.ResetItem(Me.listItems.Count - 1) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If Me.ListBox1.SelectedItem IsNot Nothing Then 'Edit the current item. Me.listItems(Me.ListBox1.SelectedIndex) = Me.TextBox1.Text Me.listItems.ResetItem(Me.ListBox1.SelectedIndex) End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If Me.ListBox1.SelectedItem IsNot Nothing Then 'Delete the current item. Me.listItems.RemoveAt(Me.ListBox1.SelectedIndex) Me.listItems.ResetItem(Me.ListBox1.SelectedIndex) End If End Sub Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed 'Clear the old data. My.Settings.ListItems.Clear() 'Save the current data. For Each listItem As String In Me.listItems My.Settings.ListItems.Add(listItem) Next End Sub End Class
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
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.Code:My.Settings.ARRAYLIST = ListBox.Items
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)