Link to home
Start Free TrialLog in
Avatar of guyvaio
guyvaio

asked on

C# Placing a combo in one cell of a dataGridView bound to a dataTable

Hello,

I'm searching now for some hours to achieve something that should be simple : placing a combo in one particular cell (not all cells of a column) of a dataGridView bound to a dataTable. (C# framework 2.0)

In the constructor of my form, below InitializeComponent();, I've this code :

dataGridView1.DataSource = dt;
...
DataGridViewComboBoxCell combo_langue = new DataGridViewComboBoxCell();
combo_langue.Items.Add("F");
combo_langue.Items.Add("N");
combo_langue.Items.Add("E");
combo_langue.Items.Add("D");
dataGridView1.Rows[i_langue].Cells[1] = combo_langue;

But the result is always a "classical" cell.

Thanks in advance for your help,

Best regards,

Guy
Avatar of dimaj
dimaj
Flag of United States of America image

try setting that cell after your binding...
I'm guessing that your data binding is overriding your cell's configuration...

If you want your data to be bound to something, you'll have to bing it every time something is changing. After your binging has been set, update your cell with your combo_langue.

if you have no binding, everything will work just fine (i just tested it)
Avatar of guyvaio
guyvaio

ASKER

Thank you for your answer.

I'm not sure to understand your suggestion : the databinding (dataGridView1.DataSource = dt;) is already done before the setup of the cell with combo_langue.

As far as I understand, your suggestion is precisely what is already in my code.

Best regards,

Guy
ASKER CERTIFIED SOLUTION
Avatar of dimaj
dimaj
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of guyvaio

ASKER

Yes it works.
I moved this code from to constructor to form load event, and everything is now ok.
Thanks for your help,
Best regards,
Guy
I'm glad I could help!

Cheers!

dimaj