If I correctly understand what you want, this should be a solution for you.
1. Create predefined columns.
private System.Windows.Forms.DataGridViewTextBoxColumn column1;
private System.Windows.Forms.DataGridViewTextBoxColumn column2;
2. Set the
DataPropertyName
to the Excel column name.
this.column1.DataPropertyName = "ExcelCol1";
this.column1.HeaderText = "Col1";
this.column1.Name = "column1";
this.column1.Width = 50;
this.column2.DataPropertyName = "ExcelCol2";
this.column2.HeaderText = "Col2";
this.column2.Name = "column2";
this.column2.Width = 50;
3. Add the columns to the
DataGridView
this.dataGridView_VAT.Columns.AddRange(
new System.Windows.Forms.DataGridViewColumn[] {
this.column1,
this.column2});
Now when you fill the
DataTable
with values they will fall into the right columns and you can reorder the columns as you please, as the name of the column is the key, not the index.