listview总是不能够正确显示
程序代码:
using System; using System.Collections.Generic; using using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using namespace 遍历文件夹 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { listView1.Clear(); if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { textBox1.Text = folderBrowserDialog1.SelectedPath; DirectoryInfo dinfo = new DirectoryInfo(textBox1.Text); FileSystemInfo[] fsinfos = dinfo.GetFileSystemInfos(); foreach (FileSystemInfo fsinfo in fsinfos) { if (fsinfo is DirectoryInfo) { ListViewItem lstItem = new ListViewItem(); DirectoryInfo dirinfo = new DirectoryInfo(fsinfo.FullName); lstItem.SubItems.Add(dirinfo.Name); lstItem.SubItems.Add(dirinfo.FullName); lstItem.SubItems.Add(""); lstItem.SubItems.Add(dirinfo.CreationTime.ToShortDateString()); listView1.Items.Add( lstItem); listView1.View = View.Details; } else { ListViewItem lstItem = new ListViewItem(); FileInfo finfo = new FileInfo(fsinfo.FullName); lstItem.SubItems.Add(finfo.Name); lstItem.SubItems.Add(finfo.FullName); lstItem.SubItems.Add(finfo.Length.ToString()); lstItem.SubItems.Add(finfo.CreationTime.ToShortDateString()); listView1.Items.Add( lstItem); listView1.View = View.Details; } } } } private void Form1_Load(object sender, EventArgs e) { listView1.Columns.Add("文件名"); listView1.Columns.Add("路径"); listView1.Columns.Add("大小"); listView1.Columns.Add("创建日期"); } } }
很纠结~~view属性设置成了detail。可是还是不能正确显示