Search code examples
.netdatagridviewcolumn

Using DataSet with DataGridView and modifying DataGridViewColumn


How can I modify the DataGridViewColumn in a DataGridView when using DataGridView.DataSource = DataSet.Table?

OleDbConnection connection = new OleDbConnection(...);
OleDbDataAdapter adpCustomer = new OleDbDataAdapter(..);
DataSet dsCustomer = new DataSet();
adpCustomer.Fill(dsCustomer, "customer");
DataGridView dgv = new DataGridView();
dgv.DataSource = dsCustomer.Tables[0];

// TODO: modify columns to use combobox, checkbox etc.. how?

Thanks in advance.


Solution

  • You cannot modify columns. If you want a ComboBoxColumn, you'll need to add it to the DataGridView before. Add your combo box column BEFORE you bind and set its DataPropertyName so the grid will bind the correct data to that column instead of creating a new one.

    Another way to do this is, if you can, to use strong-typed DataSet, because it will automatically create CheckBoxColumns for your bool columns, etc...