DataGridView ComboBox ColumnType

sfx

Well-known member
Joined
Jan 31, 2006
Messages
46
Programming Experience
Beginner
Hi All,

How do I change a column type in a DataGridView to a ComboBox at runtime?

Cheers,

sfx
 
VB.NET:
Dim DGVCell As DataGridViewCell = New DataGridViewComboBoxCell()
 YourDGV.Columns(Your column name).CellTemplate = DGVCell

That would seem to do the trick, however without having tested it i would say that there could be problem with it not being of the same type. The other option would be to not use the designer then you could define the column type as you wish.
 
Hi Vis,

Thanks for getting back to me. Unfortunately, there is a type error when using your code (just as you posited). Namely, "Value provided for CellTemplate must be of type system.Windows.Forms.DataGridViewTextBoxCell or derive from it."

Actually, I am not using the designer to build the DataGridView's columns but am instead populating them at runtime by means of a DataSet. Or, more specificually, by means of a BindingSource Component created at runtime.

Any further help would be greatly appreciated.

Take care,

sfx
 
Perhaps I should be asking how to properly bind runtime columns to a DataGridView when the AutoGenerateColumns property of the DataGridView is set to false?
 
Back
Top