ChooseAllButton.cs 987 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Windows.Forms;
  3. namespace UAS_MES_NEW.CustomControl.ButtonUtil
  4. {
  5. public partial class ChooseAllButton : Button
  6. {
  7. DataGridView DGV;
  8. bool AllChecked = false;
  9. public ChooseAllButton()
  10. {
  11. InitializeComponent();
  12. }
  13. public void ChooseAll(DataGridView dgv)
  14. {
  15. DGV = dgv;
  16. Click += ChooseAll_Click;
  17. }
  18. private void ChooseAll_Click(object sender, EventArgs e)
  19. {
  20. if (AllChecked)
  21. {
  22. for (int i = 0; i < DGV.RowCount; i++)
  23. {
  24. DGV.Rows[i].Cells[0].Value = false;
  25. }
  26. AllChecked = false;
  27. }
  28. else
  29. {
  30. for (int i = 0; i < DGV.RowCount; i++)
  31. {
  32. DGV.Rows[i].Cells[0].Value = true;
  33. }
  34. AllChecked = true;
  35. }
  36. }
  37. }
  38. }