redrose
redrose

Reputation: 25

Bind named datagridview column with specific column in datatable

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

Answers (1)

Chris
Chris

Reputation: 8647

You are looking for the DataGridViewColumn.DataPropertyName property.

dataGridView1.Columns["Name"].DataPropertyName = "col1";

Upvotes: 4

Related Questions