Reputation: 25
I added some columns into datagridview by using the following code:
dataGridView1.Columns.Add("name");
dataGridView1.Columns.Add("age");
dataGridView1.Columns.Add("salary");
I have datatable that contains data from stored procedure
select col1,col2,col3 from emp
I know the traditional way to bind datagridview with datatable or dataset ,but the problem that I rebuilt datagridview where I put multi Headers and I merged some headers together so I want way to bind specific datatable column with specific datagridview column like
dataGridView1.column("Name") = dt.column("col1");
Upvotes: 2
Views: 14338
Reputation: 8647
You are looking for the DataGridViewColumn.DataPropertyName
property.
dataGridView1.Columns["Name"].DataPropertyName = "col1";
Upvotes: 4