【发布时间】:2013-10-20 18:03:01
【问题描述】:
我有一个表单应用程序,其中给出了多个文本框和列表视图...我想将列表视图数据显示到 csv 文件中,然后从 csv 读取数据并显示到列表视图中。代码在这里给出......在这段代码中,我没有得到期望的输出
private void btnUserInformation_Click(object sender, EventArgs e)
{
ListView view=new ListView();
string filepath=@"E:\Visual Studio Project\UserInfoTestApp\UserInfoTestApp\UserInfo.csv";
InformationInsertion();
ClearFields();
ListViewtoCSV(view, filepath);
}
public void ListViewtoCSV(ListView lv,string path)
{
string Info ="";
for (int i = 0; i < lv.Items.Count; i++)
{
for (int j = 1; j < lv.Items.Count; j++)
{
Info += lvUserInformation.Items[i].SubItems[j].Text + ",";
}
Info = Info.TrimEnd(',');
}
if (!File.Exists(path))
{
File.WriteAllText(path, Info);
}
File.AppendAllText(path, Info);
}
请写简单易懂的代码
【问题讨论】:
-
not getting desire output你能说得更具体点吗? -
对不起,我不明白。当您单击提交信息时,您将字符串保存在 csv 文件中,然后您想在 dataGridView 中查看所有 FirstName/LastName/Age?
-
我希望 listview 列的值也可以在单击提交时写入 csv 文件...图像只是为了显示您的表单是这样的..否则我的代码有错误.. . 我需要你编写简单易懂的代码,这样我就可以很容易地理解 listview 数据如何存储到 csv 文件中......
标签: c# winforms listview csv export-to-csv