I have this code that will check the listview checkbox if the condition is met.
con = new SqlConnect(); con.SqlQuery("Select * from EmployeeDeduct where EmployeeeID = @empID"); con.cmd.Parameters.AddWithValue("@empID", lblEmpID.Text); sda = new SqlDataAdapter(con.cmd); ds = new DataSet(); sda.Fill(ds); con.cmd.Connection.Close(); if (ds.Tables[0].Rows.Count > 0) { for (int g = 0; g < ds.Tables[0].Rows.Count; g++) { con = new SqlConnect(); con.SqlQuery("Select * from DeductionInfo"); sda = new SqlDataAdapter(con.cmd); DataSet ds2 = new DataSet(); sda.Fill(ds2); con.cmd.Connection.Close(); if (ds2.Tables[0].Rows.Count > 0) { for (int j = 0; j < ds2.Tables[0].Rows.Count; j++) { if (ds.Tables[0].Rows[g].ItemArray[0].ToString().Contains(ds2.Tables[0].Rows[j].ItemArray[6].ToString())) { LvDeductions.Items[j].Checked = true; } } }
I have it inside textbox textchanged. When I click the listview value, the checkbox will be checked according to db values, but when I click another item, the previous checkboxes still have checked and it will just add a check on checkboxes inside the listview. <pre> What I have tried: I put ELSE statement with LvDeductions.Items[j].Checked = false; but when I do, it uncheck the boxes that does not meet the condition but only check one box instead of two or more.
LvDeductions
DeductionInfo
con = new SqlConnect(); con.SqlQuery("Select * from DeductionInfo"); ListViewDed(); //LvDeductions.Items.Clear(); con = new SqlConnect(); con.SqlQuery("Select Firstname, Lastname, Department, Position from EmpRecord inner join EmpRecord2 on EmpRecord.empID = EmpRecord2.empID where EmpRecord.empID = @id"); con.cmd.Parameters.AddWithValue("@id", lblEmpID.Text); sdr = con.cmd.ExecuteReader(); if (sdr.Read()) { lblEmployeeName.Text = sdr[1].ToString() + "," + " " + sdr[0].ToString(); lblEmpDept.Text = sdr[2].ToString() + "," + " " + sdr[3].ToString(); } con = new SqlConnect(); con.SqlQuery("Select * from EmployeeDeduct where EmployeeeID = @empID"); con.cmd.Parameters.AddWithValue("@empID", lblEmpID.Text); sda = new SqlDataAdapter(con.cmd); ds = new DataSet(); sda.Fill(ds); con.cmd.Connection.Close(); if (ds.Tables[0].Rows.Count > 0) { for (int g = 0; g < ds.Tables[0].Rows.Count; g++) { con = new SqlConnect(); con.SqlQuery("Select * from DeductionInfo"); sda = new SqlDataAdapter(con.cmd); DataSet ds2 = new DataSet(); sda.Fill(ds2); con.cmd.Connection.Close(); if (ds2.Tables[0].Rows.Count > 0) { for (int j = 0; j < ds2.Tables[0].Rows.Count; j++) { if (ds.Tables[0].Rows[g].ItemArray[0].ToString() == ds2.Tables[0].Rows[j].ItemArray[6].ToString()) { LvDeductions.Items[j].Checked = true; } } } } }
LvDeductions.Items[j].Checked = true;
con = new SqlConnect(); con.SqlQuery("Select * from DeductionInfo where DeductID like @id"); con.cmd.Parameters.AddWithValue("@id", ds2.Tables[0].Rows[j].ItemArray[6].ToString()+"");
con.cmd.Parameters.AddWithValue("@id", ds2.Tables[0].Rows[j].ItemArray[6].ToString()+"%");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)