0

How do i solve the error that originates from the below code.

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;

            }
2
Contributors
4
Replies
16
Views
4 Months
Discussion Span
Last Post by ddanbe
0

dgvPrint is a datagridview with three columns,the first one has checkboxes for selecting the employees for which the report is to generated,the second one has the ID of the employee and the third one has the name of the employee..So what happens is that when i select the department from the combobox which has a list of the different departments,the datagridview(dgvprint) is not populated with the names of the employees in the selected department hence displaying the error "rows cannot be programmatically added to the datagridview rows collection"

0

Am trying to upgrade my windows application to enable a user to generate individual reports for more that one employee as it currently only allows the user to generate a report for one employee by clicking the name of the employee in the datagridview for which the report is to be generated (this works perfectly). So am trying to change it so that it can allow the user to use a checkbox to select the employees for which the report is to be generated. Any advice on any other options i could use is highly welcome

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.