Click here to Skip to main content
14,244,275 members
Rate this:
Please Sign up or sign in to vote.
See more:
<pre>DataSet info1 = this.GetData.getInfo("SELECT 0 AS EmpNo,Er.EmpID,(Er.FName&''&Er.LName) AS [Employee Name], Ed.DeptNo AS [Department No],Er.Gender AS [Sex] FROM (EmpRegist AS Er INNER JOIN EmployeeDept AS Ed ON Er.EmpId = Ed.EmpId)  WHERE Ed.DeptId=" + (object)DpetID + " AND  Ed.Status=0  AND Er.EmpStatus=1 ORDER BY " + str, "EmployeeDept");
            if (info1.Tables[0].Rows.Count > 0)
            {
                for (int index = 0; index < info.Tables[0].Rows.Count; ++index)
//Error Appears on the code below
                    this.dgvPrint.Rows.Add((object)0, (object)(index + 1), (object)info1.Tables[0].Rows[index]["Employee Name"].ToString(), (object)info1.Tables[0].Rows[index]["Dept No"].ToString(), (object)info1.Tables[0].Rows[index]["EmpId"].ToString());
                        }
            if (this.dgvPrint.Rows.Count > 0)
                this.btnPrint.Enabled = true;
            else
                this.btnPrint.Enabled = false;
                        

        }


What I have tried:

How can i solve the error that says "<blockquote class="quote"><div class="op">Quote:</div>Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound</blockquote>"
Posted
Updated 15-Jun-17 20:57pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Quote:
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound

I would say it is quiet clear... As you grid now use to display some data source (hence data-bound), you can not alter it directly...
You have to add rows to the data source and refresh the display...
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100