change type of the selected cell on datagridview when cell is clicked.

I am populating a datagridview with two text columns from the output of a sql stored procedure. I want the user to be able to click on any cell in the grid and see a drop down list of values populated from another database table, one per each column, which they can select from to override the cell content from the initial datasource. i.e I want to change the type of the selected cell from datagridviewtextboxcolumn to datagridviewcomboboxcolumn when the cell is clicked.  Is there any way of doing this?

Who is Participating?
Priest04Connect With a Mentor Commented:
No I dont, but I dont believe it is hard, you know the best the logic of your application. I will give some guidance links

how to create DataGridViewComboBoxColumn, insert it at desired location, and populate it

then you need to loop through each row and set the value from textbox to ComboBox cell. Note that value from textboxcell MUST exists in a comboboxcell, otherwise you will have to add this entry manually in a comboboxcolumn list.

example c# code

foreach (DataGridViewRow dr in dataGridView1.Rows)
    dr.Cells[1].Value = dr.Cells[0].Value; // index 0 is the index of textbox column, and index 1 is the index of combobox column

and in the end remove the textbox column

dataGridView1.Rows.RemoveAt(0); // index of textbox column is 0
AlHal2Author Commented:
What about setting each cell in the grid to a combobox.
The text property of the combobox are the contents of the data table.
At the moment each cell of the grid is like a textbox and is populated by the contents of the data table.
Yuu cannot change type of a datagridview cell, this is not possible. You would need to add comboboxcolumn (have it visible = false, copy data from textboxcell to new comboboxcell, remove textboxcell, and make comboboxcolumn visible.
AlHal2Author Commented:
Do you have any sample code for this?
AlHal2Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.