[英]C# code showing multiple removeable drives window 8
Below is the C# code that I'm using to get all the removeable drives and then populate the combobox
with this list: 以下是我用来获取所有可移动驱动器的C#代码,然后使用此列表填充
combobox
:
comboBox1.DataSource = DriveInfo.GetDrives()
.Where(drive => drive.DriveType == DriveType.Removable).ToList();
The code works perfectly but with one exception, it shows two removable drives in the combo box while I've attached only one. 该代码运行正常,但有一个例外,它在组合框中显示了两个可移动驱动器,而我仅附加了一个。
Is there any way that I can get only one ie the one I've attached at the USB port. 有什么办法可以使我只能获得一个,即我在USB端口上连接的那个。 I'm using Windows 8 OS.
我正在使用Windows 8 OS。
Use drive.IsReady
使用
drive.IsReady
Hopes you are making Removal Drive Security!!!! 希望您正在制作移动硬盘安全保护!!!!
Try this 尝试这个
comboBox1.DataSource = DriveInfo.GetDrives()
.Where(drive => drive.DriveType == DriveType.Removable && drive.IsReady).ToList()
thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.