Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
<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

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...
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900