【发布时间】:2020-10-08 06:54:34
【问题描述】:
我从 csv 读取到一个对象。我使用了 c# windows 窗体。看起来一切正常,但我不明白如何将每个对象放入 ListView。 这是我的主要表格。
using System.Linq;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApp10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
List<Duomenys> values = File.ReadAllLines("duomenys.csv").Skip(1)
.Select(Duomenys.FromCsv).ToList();
}
}
}
这是我的课
using System.Linq;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApp10
{
class Duomenys
{
public string vardas { get; set; }
public string adresas { get; set; }
public string kodas { get; set; }
public decimal suma { get; set; }
public decimal suma2 { get; set; }
public static Duomenys FromCsv(string csvLine)
{
string[] values = csvLine.Split(';');
Duomenys info = new Duomenys();
info.vardas = Convert.ToString(values[0]);
info.adresas = Convert.ToString(values[1]);
info.kodas = Convert.ToString(values[2]);
info.suma = Convert.ToDecimal(values[3]);
info.suma2 = Convert.ToDecimal(values[4]);
return info;
}
}
}
如何输出到 ListView ?
【问题讨论】:
标签: c# winforms csv class listview