Hi,
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

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)
        {
            rowValue = streamReader.ReadLine();
            cellValue = rowValue.Split(',');
            dataGridView1.Rows.Add(cellValue);
        }

        streamReader.Close();
    }
    else
    {
        MessageBox.Show("No File is Selected");
    }
}

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

rowValue = streamReader.ReadLine();

If you just read a line (like at code-line 20) before the loop, it will skip the first line in the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.