C#中如何将硬盘中的txt文件倒入到ListView中逐行显示

2024-12-24 17:15:27
推荐回答(1个)
回答1:

string s;
StreamReader sr = new StreamReader(@"C:\Documents and Settings\XPMUser\桌面\ttt.txt");
s = sr.ReadToEnd();
sr.Close();
string[] sentence = s.Split('\n');
foreach (string ss in sentence)
{
string[] words = ss.Split(' ');
listView1.Items.Add(new ListViewItem(words));
}添加足够的列,注意要将listview的view 设置为details才能看到细节