ChooseAllButton.cs 1.1 KB

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