How do I use a bound combobox in a DataGridView?
Posted on 2007-08-08
Hi, I have a dataset with 2 tables:
Payment (PaymentId, Date, Description, Amount, PaymentMethodId)
PaymentMethod (PaymentMethodId, Description)
The first table contains details of any Payments that we receive and is displayed in the datagridview.
The second is a lookup table which lists the methods of payment (ie. cash, cheque, credit card) and should appear as a combobox in the grid.
As you can see there is a foreign key (PaymentMethodId) between the two tables.
I'm binding the DataGridViewComboBoxColumn as follows:
comboboxColumn.DataSource = myDataset.PaymentMethod;
comboboxColumn.ValueMember = "PaymentMethodId";
comboboxColumn.DisplayMember = "Description";
Then adding it to the grid. But when the grid displays I receive the following data error "DataGridViewComboBoxCell value is not valid" and the cell value contains the Id (such as 1) rather than the Description (such as "Cash").
Any ideas what I'm doing wrong? Or does anyone know of any sample projects for this scenario?
Thanks in advance