【发布时间】:2023-03-20 02:20:02
【问题描述】:
所以我试图用我放入 txt 文件的名称填充列表框。 当我使用 Console.WriteLine(naam) 时,它实际上显示了文件中的名称,但我无法将它们放入列表框中。有谁知道这个问题的解决方案?谢谢你的到来。
public void PopulateList( ListBox list, string file)
{
string naam;
string sourcepath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string myfile = System.IO.Path.Combine(sourcepath, file);
StreamReader reader = File.OpenText(myfile);
naam = reader.ReadLine();
while (naam != null)
{
list.Items.Add(naam);
list.Items.Add(Environment.NewLine);
naam = reader.ReadLine();
}
reader.Close();
}
【问题讨论】:
-
感谢您的帮助,我找到了解决方案,这只是一个愚蠢的错误..
标签: c# wpf listbox streamreader