Question Load Combo Box from text file

CoachBarker

Well-known member
Joined
Jul 26, 2007
Messages
133
Programming Experience
1-3
I have one combo box on a form that I would like to load from a text file. This I can do, now I would like to be able to add items (extensions) into the combo box and have the items added directly to the text file.

To load the combo box I am doing this and calling it on Form Load;
VB.NET:
Expand Collapse Copy
Public Sub loadComboBox()
    'Create a collection and initialise it using the array returned by reading the lines of the file.
    Dim lines As New List(Of String)(IO.File.ReadAllLines("../../TextFiles\ComboBox.txt"))
    For Each item As String In lines
        Me.cboFileExtension.Items.Add(item)
        Me.cboFileExtension.Sorted = True
        Me.cboFileExtension.SelectedIndex = 0
    Next
End Sub

Somewhere I had the code to do what I want but seems I lost it somehow:eek:

Any help?
 
VB.NET:
Expand Collapse Copy
        Dim sw As StreamWriter = New StreamWriter("C:\ComboboxOutput.txt", False)

        For i As Integer = 0 To ComboBox1.Items.Count - 1 Step 1
            sw.WriteLine(ComboBox1.Items(i).ToString())
        Next
        sw.Close()
 
Back
Top