Question Add item to Combobox

Mathh

Member
Joined
May 16, 2013
Messages
7
Programming Experience
Beginner
Hello!

Currently, I'm working on project, where I would like to use two Windows Forms. First one should be Administrator Form and the second one User form.

I would like to know, if it's possible to call String Collection Editor for combobox after button1.click_event in first form, and add items to combobox collection and save them to be available after restarting the application. (Combobox will be available in second form). I had one example with ItemBox, unfortunately it's for one item, and I want to allow the administrator to put more than one new item.

Is it possible?

Thank you in advance for your help!
 
What you're trying to achieve is possible but the way you're trying to achieve it is not. How could you open the String Collection Editor when it's part of Visual Studio? If you want the user to be able to edit the contents of the ComboBox then you'll have to provide your own form to do so. That's quire easy because it's simply a multiline TextBox.

To be able to remember changes made, the data must be stored outside the EXE. The obvious option is to use My.Settings. Open the Settings page of the project properties and add a StringCollection. That will be where you store your items and you can access it via My.Settings in code. If you don't have any items initially, just add a dummy one, save it and then delete it again to ensure that the XML code for the collection is generated.

When it comes time to edit the items in a TextBox, load the data like this:
VB.NET:
myTextBox.Lines = My.Settings.MyStringCollection.Cast(Of String)().ToArray()
and save it like this:
VB.NET:
My.Settings.MyStringCollection.Clear()
My.Settings.MyStringCollection.AddRange(myTextBox.Lines)
 
Back
Top