I have a set of data coming into a DataGridView from another DataGridView (described here, question solved).
I now wish to add two new columns to my DataSet, one Integer, one Boolean, with the Integer column being of type DataGridViewNumericUpDownColumn (gratefully thieved from this MSDN page), and the Boolean column being of DataGridViewCheckBoxColumn type.
If I add the columns directly to the DataSet, I can’t seem to specify the DataGridViewColumn type for the Integer column.
If I set the DataSet as the DataSource of the DataGridView, then add the columns to the DataGridView, then the columns exist, but aren’t bound back to the DataSet, which does not contain those columns.
How do I get these two columns to bind to the DataGridViewColumns, with the correct column type?
To do this you need to set the
AutoGenerateColumnsproperty of theDataGridViewtofalseand add the columns yourself to both theDataSetand theDataGridView.DataGridViewcolumns have theDataPropertyNameproperty which allows you to set up binding to the underlyingDataSource.What you can do is have the
AutoGenerateColumnsproperty set true, add the DataSet as the DataSource for the grid (thus getting most of your needed columns), then turn AutoGenerateColumns off and add the Integer and Boolean columns to the dataset and the grid.Below is some example code, binding against a DataTable:
I haven’t implemented the NumericUpDown column type, but it should work just the same as the check box column type shown.