My DataTable
has three columns fetched from a database, while I need to bind only two columns of it to a DataGridView
. Can you please help me with
Create the columns for the DataGridView yourself. Try something like this.
DataGridView dataGridView1 = new DataGridView();
BindingSource bindingSource1 = new BindingSource();
dataGridView1.ColumnCount = 2;
dataGridView1.Columns[0].Name = "Field1";
dataGridView1.Columns[0].DataPropertyName = "Field1";
dataGridView1.Columns[1].Name = "Field2";
dataGridView1.Columns[1].DataPropertyName = "Field2";
bindingSource1.DataSource = GetDataTable();
dataGridView1.DataSource = bindingSource1;