Passing of a dynamic checked box to another box.

Feb 5 2021 7:41 AM
Hi, I am new to this. i would like to pass over checked values from form1 to form2 however i am currently using the dynamic checkbox, thus the output i would like use for another sql query in form2.
 
Here is my code:
  1. private void populateSalesCategory()  
  2. {  
  3. con.Connect();  
  4. string selectQuery = "SELECT * FROM SalesCategory";  
  5. using (SqlDataAdapter sda = new SqlDataAdapter(selectQuery, con.conn))  
  6. {  
  7. //Fill the DataTable with records from table  
  8. DataTable scdt = new DataTable();  
  9. sda.Fill(scdt);  
  10. //Loop and add CheckBoxes to SalesCategoryPanel.  
  11. string sc = "";  
  12. foreach (DataRow row in scdt.Rows)  
  13. {  
  14. CheckBox chk = new CheckBox();  
  15. chk.Width = 100;  
  16. chk.Text = row["CategoryName"].ToString();  
  17. chk.CheckedChanged += new EventHandler(changecheck);  
  18. salesCategoryPanel.Controls.Add(chk);  
  19. }  
  20. }  
  21. }  
  22. private void changecheck(object sender, EventArgs e)  
  23. {  
  24. CheckBox chk = sender as CheckBox;  
  25. if (chk.Checked)  
  26. {  
  27. MessageBox.Show(chk.Text);  
  28. }  
  29. }  
Thanks a lot.

Answers (1)