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?

AlHal2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
0
Priest04Commented:
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.
0
AlHal2Author Commented:
Do you have any sample code for this?
0
Priest04Commented:
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

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx

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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlHal2Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.