Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

C#
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++;


        }
Posted
Updated 18-Apr-18 22:35pm

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900