第1个回答 2013-04-25
/// <summary>
/// 获取本地磁盘
/// </summary>
private void InitListData()
{
DriveInfo[] drivers = DriveInfo.GetDrives();
foreach (DriveInfo driver in drivers)
{
string name = "(" + driver.Name.Substring(0, driver.Name.IndexOf(":") + 1) + ")";
ListViewItem node = new ListViewItem();
if (driver.DriveType != DriveType.CDRom)
{
node.Text = "本地磁盘" + name;
//node.ImageKey = "Hard Drive.ico";
node.Tag = driver.RootDirectory.FullName;
this.LsbSubject.Items.Add(node);
}
else if (driver.DriveType == DriveType.CDRom)
{
node.Text = "光盘" + name;
//node.ImageKey = "CD-ROM Drive.ico";
node.Tag = string.Empty;
this.LsbSubject.Items.Add(node);
}
}
}