【发布时间】:2020-07-15 22:38:51
【问题描述】:
我一直在尝试将我的程序从 winForms 迁移到 UWP 作为学习练习;我是 C# 新手。
在我使用的 winForms 代码中:
private void BindData(string filePath)
{
DataTable dt = new DataTable();
string[] lines = File.ReadAllLines(filePath);
if (lines.Length > 0)
{
//first line to create header
globals.count = lines.Length;
string firstLine = lines[0];
string[] headerLabels = firstLine.Split(',');
foreach (string headerWord in headerLabels)
{
dt.Columns.Add(new DataColumn(headerWord));
}
//For Data
for (int i = 1; i < 100; i++)
{
string[] dataWords = lines[i].Split(',');
DataRow dr = dt.NewRow();
int columnIndex = 0;
foreach (string headerWord in headerLabels)
{
dr[headerWord] = dataWords[columnIndex++];
}
dt.Rows.Add(dr);
}
}
}
我怎样才能复制这个。 我尝试关注this guide 和this guide
【问题讨论】:
-
在 CSV 有一个 RFC 记录它十多年后,微软真的应该知道不要写这样的垃圾。即:如果您尝试逐行读取 CSV 文件,那么您做错了。请咨询RFC 4180 Common Format and MIME Type for Comma-Separated Values (CSV) Files 以了解CSV 面向字符的流协议。您使用 CSVFileReader 类的第一个链接是一个更好的示例。
标签: c# gridview uwp datagridview datagrid