Dynamically added CheckBox column disabled in GridView

I am dynamically adding Boolean column to DataSet. The DataSet is a DataSource for the GridView that automatically generates columns.

Problem: The checkboxes for this dynamically created column are disabled. How do 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 the GridView generates CheckBoxes for the boolean box? (And why doesn't setting ReadOnly to False have any effect?)

Thanks!

0


a source to share


3 answers


You should probably add a handler for the CellContentClick event and cancel the value the cell already has. For instance:



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;
            }
}

      

+1


a source


I believe they will be automatically disabled until they matter.



DataRow row = ds.Tables["Transactions"].NewRow();
row("Retry") = true;
ds.Tables["Transactions"].Rows.Add(row)

      

0


a source


Set Boolean to true. Its default value is false. Hope this helps.

-1


a source







All Articles