private void btnLoadData_Click(object sender, EventArgs e)
{
string rowValue;
string[] cellValue;
if (System.IO.File.Exists(txtPath.Text))
System.IO.StreamReader streamReader = new StreamReader(txtPath.Text);
// Reading header
rowValue = streamReader.ReadLine();
cellValue = rowValue.Split(',');
for (int i = 0; i <= cellValue.Count() - 1; i++)
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.Name = cellValue[i];
column.HeaderText = cellValue[i];
dataGridView1.Columns.Add(column);
}
// Reading content
while (streamReader.Peek() != -1)
dataGridView1.Rows.Add(cellValue);
streamReader.Close();
else
MessageBox.Show("No File is Selected");