I'm trying to import CSV and display the data in DataGridView by using the way that i can understand.
Here is the code and the explanation that i understand how it works so far.
Please do correct me if i miss understand.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace test2
{
public partial class Form1 : Form
{
//Open the choose GUI to choose the file that we want to import
OpenFileDialog openFile = new OpenFileDialog();
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
//if open successfully, then apply streamReader to it
if (openFile.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new StreamReader(openFile.FileName);
//read the data in the file by using readLine
var rl = sr.ReadLine();
// If the rl is not null, then print (is it correct?)....
if(rl != null)
{
///code to print data
}
}
}
//filter out the csv file.
private void Form1_Load_1(object sender, EventArgs e)
{
openFile.Filter = "CSV|*.csv";
}
}
}
Now, i'm trying to print the data.
I know i need to use DataGridView.DataSource to print the data(correct me if i'm wrong) but i have no idea how to apply.
So, is my explain is true or is there anything i have add???
--beginner.