I'm trying to do the following:
- Store items from ComboBox in My.Settings (datatype doesn't matter, but need suggestions).
- Retrieve these items to populate a ComboBox on formload.
- Also display these items (1 item per line) in TextBox, where I can edit and save the edits to both My.Settings and the ComboBox.
I'm a little lost, how should I go about doing this?
Existing Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Labels.LoadSettings()
txtNumOfLabels.Text = Labels.numOfLabels
cboItem.Items.Clear()
For Each s As String In Labels.items
cboItem.Items.Add(s)
Next
End Sub
Public Shared items As New Specialized.StringCollection
Shared Sub LoadSettings()
Try
items = My.Settings("Items")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation)
End Try
End Sub
Private Sub Options_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
For Each s As String In Labels.items
txtItems.AppendText(s + Environment.NewLine)
Next
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim itemCollection As New Specialized.StringCollection
For Each s As String In txtItems.Lines
itemCollection.Add(s)
Next
My.Settings("Items") = itemCollection
My.Settings.Save()
Labels.LoadSettings()
Form1.cboItem.Items.Clear()
For Each s As String In Labels.items
Form1.cboItem.Items.Add(s)
Next
Me.Close()
End Sub
But this code won't save the values properly, or display them properly in the combobox or textbox.