Note that there are some explanatory texts on larger screens.

plurals
  1. POdataGridView columns header
    primarykey
    data
    text
    <p>I am reading excel file into dataGridView in C#.NET, however it renders columns header for the first row, how can I eliminate rendering columns header so all rows will look same?</p> <p>I have openDialogBox1 and button1 to open this dialog and choose excel file:</p> <pre><code>private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { Excel.Application excelApp = new Excel.Application(); //excelApp.Visible = true; Excel.Workbook theWorkbook = excelApp.Workbooks.Open(openFileDialog1.FileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true); Excel.Sheets sheets = theWorkbook.Worksheets; Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1); /* for (int i = 1; i &lt;= 3; i++) { Excel.Range range = worksheet.get_Range("A"+i.ToString(), "B" + i.ToString()); dataGridView1.DataSource = rangeTable(range); } */ Excel.Range range = worksheet.get_Range("A1", "B3"); dataGridView1.DataSource = rangeTable(range); } } private DataTable rangeTable(Excel.Range range) { DataTable dataTable = new DataTable(); int rowCnt = range.Rows.Count; int colCnt = range.Columns.Count; for (int i = 1; i &lt;= rowCnt; i++) { DataRow newRow = dataTable.NewRow(); for (int j = 1; j &lt;= colCnt; j++) { if (i == 1) { dataTable.Columns.Add(((Excel.Range)range.get_Item(i, j)).Value2.ToString(), typeof(string)); } else { newRow[j - 1] = ((Excel.Range)range.get_Item(i, j)).Value2; } } if (i &gt; 1) { dataTable.Rows.Add(newRow); } } return dataTable; } </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload