Multiple combo boxes in a datagridview
I am using a datagridview which has two columns as combobox columns. The moment I click on second combobox column, an exception "Datagridviewcombocellvalue is not valid" is raised. What can be the reason?
I am using a datagridview which has two columns as combobox columns. The moment I click on second combobox column, an exception "Datagridviewcombocellvalue is not valid" is raised. What can be the reason?
Naveen Aggarwal,
In order to get satisfying answer for your question, you need to provide more information on your problem. Actually there are many different situations that cause this kind of problem. Searching in MSDN forums, you will see that this is common question and there are many related threads on the topic.
1. DataGridViewComboBoxColumn value is not valid
The thread includes many situations provided by the community members:
This error usually occurs when the cell Value does not correspond to an entry in the combobox's Items collection. The error is probably raised for a particular cell. Check if its Value is present in the DataSource's ValueMember...
If the GUID column in your first table is also the PK for the table and you are getting the DataError event when the user is creating a new row, the problem here is that the default cell value for the new row is null, so similar issue is occurring. You can handle the DefaultValuesNeeded event to provide a default value other than null for the GUID column/cell.
2. DataGridView Combo Box Cell value is not valid
I manage to recreate your scenario. I feel that the foreignkey name in your table 1 is not same as the primarykey name in table2.
So for the datapropertyname - pl set it to the exact column name of your foreign key of table 1.
Hope the two threads above can give you some idea.