ABANDOND ACOUNT ABANDOND ACOUNT - 2 months ago 16
Vb.net Question

How to load a ComboBox with Items from a text file

What is the simplest way of importing items from a text file into a

ComboBox
control? The text file contains multiple lines. I need to add each line from the text file as an item in the combo box.

Answer

If the format of the text file is one combo box item per line, and you want to load them into a WinForm ComboBox control, then this would be the simplest way to do it:

ComboBox1.Items.AddRange(File.ReadAllLines(filePath))

You'll need to add Imports System.IO to the top of the code file. Either that or specify the full name of the File class:

ComboBox1.Items.AddRange(System.IO.File.ReadAllLines(filePath))
Comments