I have a datagridview its datasource is set to a data view -> data table and rows & columns are auto generated at run time.
dtable.Columns.Add("1", typeof(int));
dtable.Columns.Add("2", typeof(string));
dtable.Columns.Add("3", typeof(string));
datagridview1.DataSource = dtable;
I want column 3 to be a drop down type and have 3 options in it. How do I do that at run time as I only populate the grid at run time.
You can add columns to a
DataGridViewprogramatically.In your situation what you need to do is hide the column 3 that is generated when you bind to the
DataTableand then add aDataGridViewComboBoxColumnto the grid which has column three’s name as itsDataPropertyNameproperty.You then assign a datasource to this column where that datasource holds the three options you want to appear in the grid.
The
DataGridViewComboBoxColumnalso hasValueMemberandDisplayMemberproperties that allow you control what gets set in the grid datasource (ValueMember) and what is displayed.