Adding Combobox to DataGridView via Datatable

I have DataGridView, and I fill it through DataTable. On initialization, I add DataColumnsin DataTableand then set the DataSourceDataGridView to a DataTable. Here is the code:

DataTable mTable    = new DataTable("Test");

DataColumn  col = new DataColumn;
col.DataType      = System.Type.GetType("System.Boolean");
col.ColumnName  = "First";
col.ReadOnly    = false;
mTable.Columns.Add(col);

col            = new DataColumn;
col.DataType    = System.Type.GetType("System.String");
col.ColumnName  = "Second";
col.ReadOnly    = false;
mTable.Columns.Add(col);

this.myGridView.DataSource = mTable;

This works great, but I want to make one of the showup columns as combobox. I think I need to do something with the Column data type, but I'm not sure how to do it. Can someone give me a pointer to this?

+3
source share
2 answers

This is old, but I thought I would try to answer it one way or another since I had the same question.

, DataTable DataGridViewComboBoxColumn. DataColumn System.Data, DataGridView * Columns System.Windows.Forms.

, : DataTable DataGridView, DataTable DataGridView . Columns DataGridView, , DataTable . , "ColumnType". - DataGridViewTextBoxColumn, DataGridViewComboBoxColumn.

+1

: DataGridViewComboBoxColumn column1 = new DataGridViewComboBoxColumn()

0

Source: https://habr.com/ru/post/1732989/


All Articles