-
November 5th, 2013, 07:36 PM
#1
Datagridview giving errors on adding a new row on the comboboxcell
Hello,
I have problems with a comboboxcolumn in a datagridview: As I want to insert a new row, I get a "System.ArgumentException: The value of the DataGridViewComboBoxCell is invalid." I am using Linq to SQL to populate the data from different tables:
- Table Customer (ID (key), Name,...)
- Table Address (ID (key), CustomerID, Street,...)
- Table ContactPerson (ID (key), AddressID, Name, Title,...)
My Linq query to populate the ContactDataGridView(which is bound to the TextBox RelationIdTextBox), is following:
Code:
var y = from r in BH.Relations
where r.RelationID.ToString() == relationIDTextBox.Text
join v in BH.Addresss on r.RelationID equals v.RelationID
join c in BH.ContactPersons on v.AddressID equals c.AddressID
select c;
contactPersonsBindingSource.DataSource = y;
ContactDataGridView.DataSource = contactPersonsBindingSource;
This works fine.
In this ContactDataGridView I have a ComboBoxCell AddressID which populates the streetnames instead of the AddressID, using following linq query:
Code:
var addr = from a in BH.Addresss
where a.RelationID.ToString() == relationIDTextBox.Text
select new { AddressID = a.AddressID, Street = a.Street };
ContactAddressBindingSource = addr;
This works fine as well.
That is, untill I want to add a new row in this datagridview. Then I get the error "System.ArgumentException: The value of the DataGridViewComboBoxCell is invalid."
Can anyone help to make me understand what I am doing wrong? I really cannot figure it out!
Thanks!
-
November 5th, 2013, 08:27 PM
#2
Re: Datagridview giving errors on adding a new row on the comboboxcell
I tried it with other tables within my Database, and I keep getting the same errors. I noticed that I only get this error when the comboboxcell may not contain null values. Now, how can I prevent this error and let the user decide which value he wants to select from within the possible values in this combobox?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|