this.dgvActiveBlocks.DataSource = this.dsBlocks.Tables[0];If you want all columns in that table to be in your grid, simply set
this.dgvActiveBlocks.AutoGenerateColumns = true;If you don't want all columns, then you have a couple of options for getting the proper columns to display in your grid:
foreach (DataGridViewColumn col in this.dataGridView1.Columns) { col.Visible = false; } this.dataGridView1.Columns["PaymentBlock"].Visible = true; this.dataGridView1.Columns["BlockDescription"].Visible = true; this.dataGridView1.Columns["RaisedBy"].Visible = true; this.dataGridView1.Columns["RaisedDate"].Visible = true; this.dataGridView1.Columns["RaisedDepartment"].Visible = true; this.dataGridView1.Columns["Status"].Visible = true;Or, you can set AutoGenerateColumns to false & add the columns programmatically:
DataGridViewTextBoxColumn[] cols = new DataGridViewTextBoxColumn[6]; cols[0] = new DataGridViewTextBoxColumn(); cols[0].DataPropertyName = "PaymentBlock"; cols[0].HeaderText = "Payment Block"; cols[1] = new DataGridViewTextBoxColumn(); cols[1].DataPropertyName = "BlockDescription"; cols[1].HeaderText = "BlockDescription"; // etc. for the rest of the columns this.dataGridView1.Columns.AddRange(cols);~~Bonnie
>foreach (DataRow dr in this.dsBlocks.Tables[0].Rows) >{ > Object[] cells = {dr["PaymentBlock"].ToString(), > dr["BlockDescription"].ToString(), > dr["RaisedBy"].ToString(), > dr["RaisedDate"].ToString(), > dr["RaisedDepartment"].ToString(), > dr["Status"]}; > > this.dgvActiveBlocks.Rows.Add(cells); >} >>