In my program there is a button to mark and the same button to uncheck a checkbox.
Example: If I click once, it marks the checkbox, if I click the button again it unchecks the check box. However, clicking again no longer marks the checkbox, after the second click the button loses the action.
Follow my code:
public frmLaudosPS()
{
InitializeComponent();
this.btn_seleciona.Click += this.marcar;
}
private void marcar(object sender, EventArgs e)
{
DataTable table = (DataTable)dgw_laudos.DataSource;
foreach (DataRow row in table.Rows)
row["SELECIONAR"] = true;
this.btn_seleciona.Click -= this.marcar;
this.btn_seleciona.Click += this.desmarcar;
}
private void desmarcar(object sender, EventArgs e)
{
DataTable table = (DataTable)dgw_laudos.DataSource;
foreach (DataRow row in table.Rows)
row["SELECIONAR"] = false;
}