- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 DataGridView
绑定(bind)到一个对象列表,我正在使用 CellFormatting
事件设置动态单元格背景颜色,如 this answer .这适用于除 DataGridViewCheckboxColumn
之外的每一列。当我单击此单元格内部(但在复选框外部)时,单元格背景更改为默认的白色。
从视觉上看,细胞选择似乎正在发生,尽管我已尽最大努力阻止它。我的单元格格式化代码设置了 SelectionBackColor
以及 BackColor
。我已经使用 CellStateChanged
事件禁用了单元格选择,并且其他列均不可选择:
private void PlayerGrid_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e){ if (e.StateChanged == DataGridViewElementStates.Selected) e.Cell.Selected = false;}
是否有额外的解决方法来覆盖复选框的单元格行为?
最佳答案
我通过将以下代码添加到 CellStateChanged
事件找到了解决方法:
if (e.Cell is DataGridViewCheckBoxCell)
e.Cell.Style.BackColor = BackgroundColor(e.Cell.RowIndex);
(BackgroundColor()
根据行计算单元格背景色。)
这可以解决问题,但可能会导致创建额外的样式对象,从而导致较大表或虚拟表出现性能问题。
关于c# - DataGridViewCheckboxCell 的背景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3660337/
DataGridViewCheckBoxCell 未被检查。我已经像这样插入了第一列 DataGridView1.Columns.Insert(0, new DataGridViewCheckBoxC
我有一个 DataGridView 绑定(bind)到一个对象列表,我正在使用 CellFormatting 事件设置动态单元格背景颜色,如 this answer .这适用于除 DataGridVi
我有一个从 DataTable 加载数据的 DataGridView,以及一个未绑定(bind)的 DataGridViewCheckBoxCells 列。 DataGridView 中的行与单独的
我创建了一个 DataGridView 控件,其中第一列是一个复选框。当我在复选框内单击时,代码会正确执行。但是,当单击发生在单元格中而不是复选框中时,代码会正确处理复选框的状态,但不会更新复选框本身
我知道复选框的大小可以像这样改变。 checkBox1.Size = new Size(10, 10); 我想用 DataGridViewCheckBoxColumn 更改 DataGridview
我有以下 DataGridViewCheckBoxCell。问题是在编辑模式下视觉更新不会立即发生,只有当我退出它时才会发生 public class CustomDataGridViewCell :
我已经将一个数据表绑定(bind)到一个DataGridView,这个数据表有一个名为“Status”的列,它是Boolean 类型。我可以通过代码将值设置为 true 或 false 就好了。 但是
我正在开发一个名为 ListingGrid 的 DataGridView,试图激活/停用已在内部的任何 DataGridViewCheckBoxCell 上“检查”的用户DataGridViewChe
我有一个 DataGridView,其中包含 1 列定义为复选框。我不确定使用哪个事件来检查 cbo 是否已选中或未选中。我一直在使用 CellValueChanged 事件,但请注意,当我选中一个框
我正在使用 DataGridViewCheckBoxCell,但我不知道如何让 ->Value 属性“正确”工作。 for (int i = this->dgvConfigs->Rows->Count
我正在使用 .NET Windows 窗体 DataGridView,并且需要编辑 DataBound 列(绑定(bind)到 bool DataTable 列)。为此,我指定了这样的单元格模板: D
有谁知道使用 DataGridViewCheckboxCell 禁用 DataGridView 中的复选框的方法吗? 我可以将其设置为只读,并设置背景颜色,但我无法让复选框本身显示为禁用状态。有什么想
我是一名优秀的程序员,十分优秀!