views:

1146

answers:

2

I'm dynamically adding a Boolean column to a DataSet. The DataSet's table is the DataSource for a GridView, which AutoGenerates the columns.

Issue: The checkboxes for this dynamically generated column are all disabled. How can I enable them?

ds.Tables["Transactions"].Columns.Add("Retry", typeof(System.Boolean));
ds.Tables["Transactions"].Columns["Retry"].ReadOnly = false;

In other words, how can I control how GridView generates the CheckBoxes for a Boolean field? (And why does setting ReadOnly to False have no effect?)

Thanks!

A: 

I believe they will be automatically disabled until they have a value.

DataRow row = ds.Tables["Transactions"].NewRow();
row("Retry") = true;
ds.Tables["Transactions"].Rows.Add(row)
hypoxide
Makes no difference. Now they're checked but still disabled.foreach (DataRow dr in ds.Tables["Transactions"].Rows){ dr.BeginEdit(); dr["Retry"] = true; dr.EndEdit();}
Mark Maslar
You're right. There's got to be some other code affecting your column.
hypoxide
A: 

You should probably add CellContentClick event handler and negate the value that the cell already has. Like:

private void dgvRaceDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
            if (e.ColumnIndex == 5)
            {
                dgvRaceDetails.Rows[e.RowIndex].Cells[5].Value =
                    !(Boolean)dgvRaceDetails.Rows[e.RowIndex].Cells[5].Value;
            }

            if (e.ColumnIndex == 6)
            {
                dgvRaceDetails.Rows[e.RowIndex].Cells[6].Value =
                    !(Boolean)dgvRaceDetails.Rows[e.RowIndex].Cells[6].Value;
            }
}
bojanskr