How to change a DataGridViewTextBoxColumn to a DataGridViewComboBoxColumn?

  • Thread starter Thread starter nvx
  • Start date Start date
N

nvx

Hi,
how can I change a DataGridViewTextBoxColumn to a
DataGridViewComboBoxColumn programmatically?

Thanks...

With regards
nvx
 
Hmm, I've experimented a bit with this thing again...

As I add a new column to a DataSet bound to a DataGridView, it leads to
automatic addition of one TextBox column into the DataGridView. After using

DataGridViewCell cell = new DataGridViewComboBoxCell();
DGV.Columns["colname"].CellTemplate = cell;

I encounter an error message "Value for the property CellTemplate has to
be of the Windows.Forms.DataGridViewTextBoxCell type or has to be
derived from this type." (I'm sorry for the translation, but the
original error message was not in English)

I wonder, am I able to change the column type upon it's automatic
creation? I guess not. How could I change the column type then? I should
definitely not add any new columns to the DataGridView as I'd have two
brand new columns instead of one then...

Maybe I could still create the column myself, remove the automatically
created one and set the data binding, but that doesn't seem to me as a
good solution. There must be a simple way how to do this...

Any ideas?

With regards
nvx


nvx napsal(a):
 
Same problem over here! If you guys find any alternative way, please
don't forget to post it here! :D
 
I had this problem in the past for a few times too. Then I stopped using
the DB designer in VS2005 and started writing my own code for working
with DB. This way I can define the type of a column as I wish before I
add it to the DataGridView and bind it to the DB table's column.

P.J.


(e-mail address removed) napsal(a):
 
Back
Top