listView1.View = View.Details;//設定檢視為詳細資訊
ColumnHeader header1 = new ColumnHeader();
header1.Width = 100; //列標頭寬
header1.Text = "第一列"; //列標頭名稱
ColumnHeader header2 = new ColumnHeader();
header2.Width = 100;
header2.Text = "第二列";
listView1.Columns.Add(header1);//新增列
listView1.Columns.Add(header2);
string path = @"G:\2.txt";//檔案路徑
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(fs, Encoding.Default))
string line = reader.ReadLine();
while (line != null)
string[] arr = line.Split(new string[] { "----" }, StringSplitOptions.None);
listView1.Items.Add(new ListViewItem(arr));
line = reader.ReadLine();
}
listView1.View = View.Details;//設定檢視為詳細資訊
ColumnHeader header1 = new ColumnHeader();
header1.Width = 100; //列標頭寬
header1.Text = "第一列"; //列標頭名稱
ColumnHeader header2 = new ColumnHeader();
header2.Width = 100;
header2.Text = "第二列";
listView1.Columns.Add(header1);//新增列
listView1.Columns.Add(header2);
string path = @"G:\2.txt";//檔案路徑
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(fs, Encoding.Default))
{
string line = reader.ReadLine();
while (line != null)
{
string[] arr = line.Split(new string[] { "----" }, StringSplitOptions.None);
listView1.Items.Add(new ListViewItem(arr));
line = reader.ReadLine();
}
}
}