C# Windows Form

C# Program to Read CSV File and Display Data in DataGridView

This tutorial demonstrates how a csv file can be used to bind data to DataGridView of C#.

The code uses System.IO.File.ReadAllText to read the file’s contents into a string. It then uses Split to break the file into lines, ignoring any blank lines.

The code then loops through the lines using Split to split the lines into fields and adding their values to the array. When it’s done, the method returns the two-dimensional array of strings.

I used this sample CSV file. 

 

Form Design:

In our first approach, we are going to create textBox, dataGridView, openFileDialog and Button Controls at design-time using the Forms designer.

 

Source Code:

Output:

8 Comments

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.