将CSV文件加载到2D数组中,然后通过列表框显示(C#) [英] Loaded CSV file into 2D array then display via listbox (C#)
本文介绍了将CSV文件加载到2D数组中,然后通过列表框显示(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最终目标是将csv文件加载到二维数组中,然后将这些数据显示到我创建的列表框中。下面的代码应该加载csv文件,但我不知道我现在如何将我创建的2D数组放入列表框中。
我尝试过:
The end goal is to load a csv file into a two-dimensional array then display those data into the listbox I created. The code below should load the csv file but I dont know how I can now get the 2D array I created into the listbox.
What I have tried:
string filePath = "data.txt"; // CSV File
int count = 0;
string[,] list = new string[6, 4];
private void App_Load(object sender, EventArgs e)
{
FileStream fstrm = new FileStream(path, FileMode.Open, FileAccess.Read);
StreamReader sread = new StreamReader(fstrm);
while (!sread.EndOfStream)
{
string line = sr.ReadLine();
string[] parts = line.Split(',');
for (int i = 0; i < parts.Length; i++)
{
list[count, i] = parts[i];
}
count++;
}
推荐答案
列表框只包含一列,所以它不会采用2D阵列。但是,请参阅 ListBox.Items属性(系统.Windows.Forms) [ ^ ]其他可能性。
A listbox contains only a single column, so it will not take a 2D array as it stands. However, see ListBox.Items Property (System.Windows.Forms)[^] for other possibilities.
这篇关于将CSV文件加载到2D数组中,然后通过列表框显示(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文