I have a ComboBox named DriveDropDown which I would like to display all removable drives. This is updated when the Refresh button is clicked. However, when I click the refresh button, nothing shows up, even though my external hard disk is connected over USB. Any ideas? Code is below.
private void RefreshButton_Click(object sender, EventArgs e)
{
DriveDropDown.Items.Remove("Press refresh to query available drives.");
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
if (d.IsReady == true)
{
if (d.DriveType == DriveType.Removable)
{
DriveDropDown.Items.Add(d.Name);
}
}
else
{
MessageBox.Show("An error occurred querying available devices.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}