1
votes

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");
1
What technology is this - Windows Forms, WPF, ASP.NET, Silverlight...? - dezfowler

1 Answers

3
votes

You are looking for the DataGridViewColumn.DataPropertyName property.

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