Marcar Vários CheckBox
Gostaria de criar um botão que marque vários checkbox em um gridview, em windows form C#, já tentei estes códigos abaixo, mas nenhum marca.
Alguem sabe como ?
Alguem sabe como ?
private void BtnMarcar_Click(object sender, EventArgs e)
{
this.itemLocacaoDataGridView.Cells["Devolver"].Value = true;
}
private void BtnMarcar_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow grid in itemLocacaoDataGridView.Rows)
{
(grid.Cells["Devolver"]. as DataGridViewCheckBoxCell).Value = true;
}
}
private void BtnMarcar_Click(object sender, EventArgs e)
{
for(int i = 0; i < this.Controls.Count; i++)
{
if(this.Controls[i] is System.Windows.Forms.CheckBox)
{
(this.Controls[i] as CheckBox).Checked = true;
}
}
}
private void BtnMarcar_Click(object sender, EventArgs e)
{
CheckBox check;
foreach(GridViewRow grid in itemLocacaoDataGridView.Rows)
{
check = (CheckBox)grid.Cells["Devolver"].Controls[0];
check.Checked = true;
}
}
Jair Souza
Curtidas 0
Respostas
Joel Rodrigues
16/01/2015
Veja se este tópico lhe ajuda: Check/Uncheck a checkbox on datagridview.
GOSTEI 0
Jair Souza
16/01/2015
Para desmarcar funcionou e ficou assim :
Mas para marcar não estou conseguindo ajustar....
private void BtnDesMarcar_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in itemLocacaoDataGridView.Rows)
{
DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)row.Cells["Devolver"];
if (chk.Value == chk.TrueValue || chk.Value != null)
{
chk.Value = chk.FalseValue;
}
itemLocacaoDataGridView.EndEdit();
}
}Mas para marcar não estou conseguindo ajustar....
GOSTEI 0
Jair Souza
16/01/2015
Assim funcionou e ficou mais curto o código :
Valeu !
private void BtnMarcar_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow _row in itemLocacaoDataGridView.Rows)
{
(_row.Cells[0] as DataGridViewCheckBoxCell).Value = true;
}
}
private void BtnDesMarcar_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow _row in itemLocacaoDataGridView.Rows)
{
(_row.Cells[0] as DataGridViewCheckBoxCell).Value = false;
}
}Valeu !
GOSTEI 0