Datagridview with combobox not working when trying to add a new row

I have a datagridview control, with a comboxboxcolumn. The datagridview control is populated using Linq to SQL, and the comboboxcolumn is populated using Linq to SQL as well. Everything works fine when I am editing an existing row's comboboxcolumn, but when I try and add a new row in the datagridview control, I get the following error message.

Here's all the code I use to populate my datagridview control, as well as my comboboxcolumn.
private void btnTimeGetTime_Click(object sender, EventArgs e)
        {
            try
            {
                OperationsDataContext opDC = new OperationsDataContext();
                dgTime.DataSource = null;

                dgTime.DataSource = opDC.ProjectHours_GetByProjectIDAndWeekEndingDate(Convert.ToInt32(cboTimeProject.SelectedValue), dtWeekEnding.Value);

                AddComboBoxColumns();

                dgTime.Columns["ProjectHourID"].ReadOnly = true;
                dgTime.Columns["WeekEndingDate"].ReadOnly = true;
                dgTime.Columns["TaskID"].ReadOnly = true;

                dgTime.AutoResizeColumns();
            }
            catch (Exception ex)
            {
            }
        }

private void AddComboBoxColumns()
        {
            DataGridViewComboBoxColumn comboboxColumn;
            comboboxColumn = CreateComboBoxColumn();
            SetAlternateChoicesUsingDataSource(comboboxColumn);
            comboboxColumn.HeaderText = "Task";
            dgTime.Columns.Insert(2, comboboxColumn);
        }

        private void SetAlternateChoicesUsingDataSource(DataGridViewComboBoxColumn comboboxColumn)
        {
            OperationsDataContext dc = new OperationsDataContext();
            {
                comboboxColumn.DataSource = dc.Tasks_GetByProjectID(Convert.ToInt32(cboTimeProject.SelectedValue));
                comboboxColumn.ValueMember = "TaskID";
                comboboxColumn.DisplayMember = "TaskName";
            }
        }

        private DataGridViewComboBoxColumn CreateComboBoxColumn()
        {
            DataGridViewComboBoxColumn column = new DataGridViewComboBoxColumn();
            {
                column.DataPropertyName = "TaskID";
                column.HeaderText = "TaskName";
                column.DropDownWidth = 160;
                column.Width = 90;
                column.MaxDropDownItems = 3;
                column.FlatStyle = FlatStyle.Flat;
            }
            return column;
        }

Open in new window

DatagridviewWithComboboxColumnNo.png
DatagridviewWithComboboxColumnWo.png
jjliu4492Asked:
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.

Friman001Commented:
To me, it looks like you need to have a value in the combobox for it to like it.  In other words, maybe see if you can have it accept null values instead or maybe you just need to put a 0 in the "tasks" column or select a value you from it before you can create it.  I just think it looks like it is not excepting the value you are starting with to create the new row.
0
Friman001Commented:
You could also try setting the first value to "" or 0.  It really looks like being able to accept null values from the first picture though.  I am just throwing out some idea.  Please write back and I will try to help point you in the right direction if I can!
0
jjliu4492Author Commented:
-Open the DataGrid properties
Click in the DataError event line
-Type _DoNothingOnDataError

        private void _DoNothingOnDataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }
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
jjliu4492Author Commented:
I found the answer on google.
0
Friman001Commented:
Cool!
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
C#

From novice to tech pro — start learning today.