我试图将行添加到通过不同方法调用的datagridview中,但是它不起作用。然后,我尝试在Click
事件中触发添加行,并且行得通。
有人可以给我提示或提示来解决此问题吗?
表格1:
private void btnTag_Click(object sender, EventArgs e)
{
var type = Type.GetType("Payroll." + dynamic_form);
dynamic form = Activator.CreateInstance(type) as Form;
form.GetEmployeeID(empid);
this.Close();
}
表格2:
public void GetEmployeeID(Dictionary<int, List<int>> emp_id)
{
//this is the add rows it's not working
dgvTaggedEmployee.Rows.Add("sample", "sample");
employee_id = emp_id;
foreach (KeyValuePair<int, List<int>> item in employee_id)
{
foreach (int value in item.Value)
{
if (dbcon.OpenCon() == true)
{
string query = "SELECT * from tbl_payroll_employee_basic where payroll_employee_id="+value.ToString()+"";
cmd = new MySqlCommand(query, dbcon.con);
read = cmd.ExecuteReader();
read.Read();
dgvTaggedEmployee.Rows.Add(read["payroll_employee_last_name"].ToString() + ", " + read["payroll_employee_first_name"].ToString() + read["payroll_employee_middle_name"].ToString(), "0");
MessageBox.Show(value.ToString(), read["payroll_employee_last_name"].ToString() + ", " + read["payroll_employee_first_name"].ToString() + read["payroll_employee_middle_name"].ToString());
dbcon.CloseCon();
}
}
}
}