I am trying to run an application which is supose to present a CSV file contents in a DataGridView.The problem is the csv file contains a line (Fiist Line) which is the Title of CSV like:
================================
Title: Titanic
Director,Year,Rate,Star1,Star2
James Cameron,1997,7.5,Leonardo DiCaprio,Kate Winslet
================================
and here is my code
Code
private void btnLoadData_Click(object sender, EventArgs e)Code
{Code
string rowValue;Code
string[] cellValue;Code
if (System.IO.File.Exists(txtPath.Text))Code
{Code
System.IO.StreamReader streamReader = new StreamReader(txtPath.Text);Code
// Reading headerCode
rowValue = streamReader.ReadLine();Code
cellValue = rowValue.Split(',');Code
for (int i = 0; i <= cellValue.Count() - 1; i++)Code
{Code
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();Code
column.Name = cellValue[i];Code
column.HeaderText = cellValue[i];Code
dataGridView1.Columns.Add(column);Code
}Code
// Reading contentCode
while (streamReader.Peek() != -1)Code
{Code
rowValue = streamReader.ReadLine();Code
cellValue = rowValue.Split(',');Code
dataGridView1.Rows.Add(cellValue);Code
}Code
streamReader.Close();Code
}Code
elseCode
{Code
MessageBox.Show("No File is Selected");Code
}Code
}1- Can you please let me know how I can skip exporting the fist line (Title: Titanic) into the DataGridView?
2- How I can retrive the Fist line and Just the Title (Titanic) and not the "Title:" to use somehwre else?
Thanks for your time and support

VulpesRank #55 · 29.2K reputationPosted Apr 16, 2012, 10:32 AM EDT
Behrouz Hosseini64 reputationPosted Apr 16, 2012, 10:40 AM EDT
just as always very helpful