0

我正在动态地将布尔列添加到数据集。DataSet 的表是 GridView 的 DataSource,它自动生成列。

问题:此动态生成的列的复选框全部被禁用。如何启用它们?

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

换句话说,我如何控制 GridView 如何为布尔字段生成 CheckBoxes?(为什么将 ReadOnly 设置为 False 没有效果?)

谢谢!

4

3 回答 3

1

您可能应该添加 CellContentClick 事件处理程序并否定单元格已有的值。喜欢:

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;
            }
}
于 2010-01-04T21:13:47.677 回答
0

我相信它们会被自动禁用,直到它们具有价值。

DataRow row = ds.Tables["Transactions"].NewRow();
row("Retry") = true;
ds.Tables["Transactions"].Rows.Add(row)
于 2009-05-06T20:09:42.907 回答
-1

将布尔值设置为 true。它的默认值为假。我希望这有帮助。

于 2015-09-16T14:05:55.137 回答