日期:2014-05-18 浏览次数:21179 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DriveInfo[] dr = DriveInfo.GetDrives();
foreach (DriveInfo dd in dr)
{
if (dd.DriveType == DriveType.CDRom) //过滤掉是光驱的 磁盘
{
return;
}
else
{
//listBox1.Items.Add(dd);
ListViewItem li = new ListViewItem();
li.SubItems[0].Text = dd.ToString();
li.SubItems.Add(dd.ToString());
listView1.Items.Add(li);
}
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedIndices != null && listView1.SelectedIndices.Count > 0)
{
ListView.SelectedIndexCollection c = listView1.SelectedIndices;
MessageBox.Show(listView1.Items[c[0]].Text);
}
}
}
}