Reputation: 1121
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!
Upvotes: 0
Views: 3220
Reputation: 1
Set the value of Boolean to true. Its default value is false. I hope this helps.
Upvotes: -1
Reputation: 11
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;
}
}
Upvotes: 1
Reputation: 11054
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)
Upvotes: 0