本文介绍了如何在C#的下拉框中列出CD驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手,我目前正在做一个项目。当找到包含数据的光盘时,我需要能够在下拉列表中列出CD驱动器。你怎么做到这一点??请帮忙我难倒!!



我尝试过:



private void ReloadDrives()//下拉框

{



Cbo1.DataSource = Environment.GetLogicalDrives();



var drives =来自DriveInfo.GetDrives()中的驱动器//获取可移动驱动器

其中Drive.DriveType == DriveType.Removable

选择云端硬盘; //列出组合框中的驱动器



Cbo1.DataSource = drives.ToList(); //列出组合框中的驱动器

}

I am new to C# and I am currently doing a project. I need to be able to list the cd drive in a drop down list when a disc is found with data on it. How do you do this?? Please help i'm stumped!!

What I have tried:

private void ReloadDrives() // Drop down box
{

Cbo1.DataSource = Environment.GetLogicalDrives();

var drives = from Drive in DriveInfo.GetDrives() // gets removable drives
where Drive.DriveType == DriveType.Removable
select Drive; // lists drives in the combobox

Cbo1.DataSource = drives.ToList(); //lists drives in combobox
}

推荐答案

Cbo1.DataSource = Directory.GetFiles(drives.ToList()[0].Name); 



如果设备未准备就绪,您需要包含一些错误处理


You'll need to include some error handling in case the device is not ready


这篇关于如何在C#的下拉框中列出CD驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:16