Hi all, I have a combo box that I want to be filled with a list of folders in a specified directory. Say, C:\Temp\Folders
There are 10 folders, labeled 1-10. In the combo box it should list those folders. Thank you!
How do I populate a combo box with a list of directories?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Rajneesh RaiRank #1,902 · 777 reputationPosted Mar 5, 2013, 3:46 PM EST
use below code to populate combobox.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DirectoryInfo obj = new DirectoryInfo("E:\\");//you can set your directory path here
DirectoryInfo[] folders = obj.GetDirectories();
comboBox1.DataSource = folders ; // Populate combobox
}
}
}
Hope it help.
justin alquist3 reputationPosted Mar 5, 2013, 4:08 PM EST
jeremiah f26 reputationPosted Dec 9, 2017, 9:11 AM EST