c# - 是否可以禁用 DataGridView 中单个列的交替行?
问题描述
我正在尝试向已填充的 DataGridView 添加一列,但我需要此列单元格的颜色全部相同,因为它是每行上所有列的总和。
我以这种方式添加列:
dt.Columns.Add("Acumulable", typeof(float));
dt.Columns["Acumulable"].Expression = "Enero+Febrero+Marzo+Abril+Mayo+Junio+Julio+Agosto+Septiembre+Octubre+Noviembre+Diciembre";
我这样设置颜色:
DGVGastosVariables.Columns["Acumulable"].DefaultCellStyle.BackColor = ColorTranslator.FromHtml("#3498DB");
它工作正常,因为它确实改变了单元格的颜色,但它保持了交替的行模式。
有没有办法特别禁用该列的交替行?
谢谢。
解决方案
尝试这个。订阅您DataGridView
的CellFormatting
活动:
private void DataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == /* Acumulable column index */)
{
e.CellStyle.BackColor = ColorTranslator.FromHtml("#3498DB");
}
}
你也可以使用CellPainting
事件。
推荐阅读
- php - PHP IMAP。停止将消息标记为已查看
- tfs - TFS 2018 构建 NuGet 推送
- python - 来自外部服务器的两台服务器之间的python ping
- c++ - 如何使用 boost::property_tree 重置 xml 元素的属性?
- json - 如何在 Swift 4 中处理嵌套的 JSON
- neural-network - 游戏 2048 的政策网络
- javascript - 获取最大值的子数组的数组键
- python - 无法从 S3 获取对象元数据。在 aws Rekognition 中检查对象键、区域和/或访问权限
- kubernetes - 连接到 Kubernetes 中的持久卷?
- r - 在 R Shiny App 中连接 UI 和 SERVER 端的对象