Reputation: 181
Public Class Form1
Private Sub btnAddCat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddCat.Click
If txtAdd.Text <> "" Then
comboBox1.Items.Add(txtAdd.Text)
txtAdd.Clear()
Else
MessageBox.Show("Fill the blanket")
End If
End Sub
End Class
If user close application should see the items but there is no items Can anyone help? thanks
Upvotes: 0
Views: 4440
Reputation: 43743
If you want the application to remember the value the next time it is run, you will need to save the value to disk. There are many different options for how to do that (e.g. text file, XML, database, registry), but for simple tasks, I'd recommend just using the built-in Settings
feature.
To use the Settings
feature, first you need to open your project properties screen. Then select the Settings
tab. Add a new setting by typing in the name and selecting a data type. For instance, you could type MyItems
for the name, and then select System.Collections.Specialized.StringCollection
as the data type. Then, in your code, you can read the current value of the setting like this (perhaps in your form's Load
event handler):
For Each i As String In My.Settings.MyItems
ComboBox1.Items.Add(i)
Next
And then you could save the list to the setting, like this (perhaps in your form's FormClosed
event handler):
My.Settings.MyItems.Clear()
For Each i As String In ComboBox1.Items
My.Settings.MyItems.Add(i)
Next
Upvotes: 1
Reputation: 34846
You need to persist the data to a data store (either the database or the file system) so that the next time the application runs, then it can check the data store and display the items to the user.
Upvotes: 1