المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Adding databound ComboBox into cells of a DataGridView



C# Programming
07-27-2012, 04:30 PM
I have a DataGridView on a form which is populated through databinding from a table in my database. I've followed, more or less, the process outlined on this MSDN page (http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx)[^ (http://msdn.microsoft.com/en-us/library/fbk67b6z.aspx)]

I've implemented the databinding both ways so that, by clicking on an "Update" button, the changes that have been made on the DataGridView is stored back into the DB. All works well, but...

Imagine the table used for the databinding being something like this:
USERS- UserID (INT)- UserName (VARCHAR)- UserType (INT)
And here's the problem, that UserType field references the identifier in a separate table like this one:
USERTYPES- UserType (INT)- UserTypeDescription (VARCHAR)
Currently, my databinding is done with a simple query like this:
SELECT * FROM USERS;
The problem is that the value displayed in the third column is an integer which means nothing to the end user. If I wasn't interested in two way databinding but only wanted to display the contents of the table in the DataGridView I could easily have overcome that problem by using the following query:
SELECT UserID, UserName, UserTypeDescription FROM USERS INNER JOIN USERTYPES ON USERS.UserType = USERTYPES.UserType;
Unfortunately I need for the end user to be able to change that value and I'd like to put a ComboBox in all the cells of that column which is populated from the USERTYPES table.

Would really appreciate some advice.