Frage

Wie kann ich deaktivieren Sie programmatisch alle Zeilen in einem DataGridViewCheckBoxColumn in einem Datagridview?

Ich kann den richtigen Wert der Checkbox erhalten mit

(bool)row.Cells[CheckBoxColumn.Index].FormattedValue

, aber das ist nur ein Getter.

Ich habe versucht, den Wert der Zelle Einstellung mit

(bool)row.Cells[CheckBoxColumn.Index].value = false

, aber das hat keinen Einfluss auf die FormattedValue.

Wie kann ich dieses Problem lösen?

War es hilfreich?

Lösung

You do sth. like:

(row.Cells[CheckBoxColumn.Index] as DataGridViewCheckBoxCell).value = false;

You just forgot to cast to the correct type, a generic DataGridViewCell doesn't know its value-type.

Andere Tipps

Haven't checked but you can try;

CheckBox cb = (row.Cells[CheckBoxColumn.Index].Controls[0] as CheckBox);
if(cb != null)
{
    cb.Checked = false;
}

It's type may be different. Just debug and cast it to what it is.

Have you tried casting the first control in the checkbox column to checkbox and then setting 'Checked' to true?

Try something to this extent.

((DataGridViewCheckBoxCell)e.Rows[0].Cells[0]).Selected = true
foreach (DataGridViewRow dr in dataGridView1.Rows)
{
  dr.Cells[0].Value = true;//sıfırın
}

If you use dataGridView1_ContextClick just for do "false" datagidviewCheckBox Column need this Code :

dataGridView1.CancelEdit();

but if you need all rows of CheckBoxColumns of DataGrid :

private void button1_Click(object sender, EventArgs e)
{
    foreach (DataGridViewRow r in dataGridView1.Rows)
    {
        r.Cells["statusBox"].Value = true;
    }
}

Loop through each row of grid view and use the find control method:

foreach ( GridViewRow row in myGridView )
{
     CheckBox checkBox = ( CheckBox ) row.FindControl( "myCheckBox" );
     checkbox.Checked = false;
}
 foreach (DataGridViewRow row in datagridviewname.Rows)

  {
    row.Cells[CheckBoxColumn1_Name].Value = false;
  }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top