How to change a DataColumn to ComboBox type column in a DataSet?

N

nvx

Hi,
how can I change a DataColumn to ComboBox type column in a DataSet?
After I add a new column into the DataSet using

MyDataSet.DataTable.Columns.Add("ColName");

I'd like to change its type so it would appear as a
DataGridViewComboBoxColumn in a DataGridView bound to this DataTable.

I also tried to create the ComboBox type column in the DataSet directly,
but failed (the Add method allows to create DataColumn columns only).

Or: could it be done by changing the column type in the DataGridView? If
so, how?

Thanks...

With regards
nvx
 
D

Dmytro Lapshyn [MVP]

Hi Nvx,

Your question doesn't have anything to do with DataSet. What you need
instead is to properly configure the ColumnStyles collection of the DataGrid
so a data column with a particular name is represented by the ComboBox
column style.
 
N

nvx

Thank you, Dmytro...

After posting the first question I looked at the DB in Access and found
out that there is not possible to set such a column type. Hence I
deleted the post you have replied to and posted another question (see
"How to change a DataGridViewTextBoxColumn to a
DataGridViewComboBoxColumn?") since I was not able to change it in the
DGV. Could you please give an exact line of code, which does this thing?

Thank you in advance.

With regards
nvx


Dmytro Lapshyn [MVP] napsal(a):
 
E

edgarrolla

Is it possible to be done in run time?
Is it actually possible to change a single cell style programmacticaly?

cheers!

nvx escreveu:
 
P

Paul Jones

Well, it can be done with

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

There's a catch though: the new column type must be derived from the
actual type or something like that, I do not remember it exactly... If
it is possible, try to create columns of needed type and you're saved
from changing theirs type in the future. I know this solution can't be
applied to every case, but to most of them it can, I guess...

P.J.


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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top