【发布时间】:2019-01-13 03:24:12
【问题描述】:
我已经使用 StreamReader 读取了一个 CSV 文件。阅读文件很容易,我有 4 列,每列都是一个字符串,但有一个(只有这一点很重要)的形式是“33 kg”,第一行是标题。我想删除 B 列中所有单元格的第一行和“kg”(其 int)。在 WindowsForms 中我可以做到这一点,但我不确定如何在 WPF 中做到这一点。
private void DataGrid_Loaded(object sender, RoutedEventArgs e)
{
// ... Get data.
var patients = new List<Patient>();
using (StreamReader reader = new StreamReader("FHDEGG.txt"))
{
while (true)
{
string line = reader.ReadLine();
if (line == null)
{
break;
}
patients.Add(new Patient(line));
}
}
// ... Set field.
this._list = patients;
// ... Use ItemsSource.
var grid = sender as DataGrid;
grid.ItemsSource = patients;
}
【问题讨论】:
-
请包含 csv 文件 FHDEGG.txt 的前几行
-
请不要在得到答案后删除您的问题。问题和答案在这里供其他人查找,如果答案对您有帮助,那么它也可以帮助其他人。
标签: c# wpf streamreader