Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my current code i applayed static 2d array and wanna load my data inside it from a csv file. The csv file contains 2000 rows and 60 columns so i need to do it with a for loop but i cant get the csv data to display it and get it inside the columns to. Now all the double numbers come underneath eachother but they need in rows of 60 double numbers. Can anyone help me get this loop to work and put the csv data inside a 2D array.

What I have tried:

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Controls;

namespace Test_INotifyPropertyChanged
{
/// <summary>
/// Interaktionslogik für MainWindow.xaml
///
public partial class MainWindow : Window
{
public ObservableCollection<string> stuff { get; set; }
public MainWindow()
{
InitializeComponent();
DataContext = this;
thing = new Thing();
int[,] prijsinflatie = new double[2000, 60];
}
public Thing thing { get; set; }
}

public class Thing
{
public ObservableCollection<string> stuff { get; set; }

public Thing()
{
stuff = new ObservableCollection<string>();

using (var reader = new StreamReader(@"D:\ActuComp\URM\Q2_Prijsinflatie.csv"))
{
List<string> listA = new List<string>();
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(';');

for (int i = 0; i < 60; i++)
{
stuff.Add(values[i]);
}
}
}
}
}
}
Posted
Updated 10-Jul-18 0:26am

1 solution

Instead of processing the CSV manually, try using this: A Fast CSV Reader[^] and bind the result to a grid-based control.
 
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