2015-01-15 2 views
0

나는이 코드를 사용하여 컴퓨터에 연결된 USB 장치를 가져 왔습니다. 여기 내가이 무엇입니까 ..목록 이름을 컴퓨터에 연결하는 USB 장치

 cbbFolder.DataSource = System.IO.DriveInfo.GetDrives() 
           .Where(d => d.DriveType == System.IO.DriveType.Removable).ToList(); 
     cbbFolder.DisplayMember = "Name"; 

cmbusb이 콤보입니다 :

I:/ 

을하지만 같은 장치 이름을받지 :

예 :이 코드는 USB (I :) 또는 이동식 디스크 (G :)

답변

1

이름을 얻으려면 VolumeLabel 속성을 사용해야합니다. Drive

의이 시도 :

 var divesList = System.IO.DriveInfo.GetDrives() 
          .Where(d => d.DriveType == System.IO.DriveType.Fixed).ToList(); 


     Dictionary<string, string> dictDrives = new Dictionary<string, string>(); 

     foreach(var item in divesList) 
     { 
      dictDrives.Add(item.Name, item.Name + " " + item.VolumeLabel); 
     } 
     cbbFolder.DataSource = new BindingSource(dictDrives, null); 
     cbbFolder.DisplayMember = "Value"; 
+0

을 cbbFolder.DisplayMember = "되는 VolumeLabel"를 교체하는 경우; usb no name show ""; –