【发布时间】:2026-02-21 11:15:01
【问题描述】:
我已经搜索了这个问题的答案。这个帖子的答案:Change Color of Button in DataGridView Cell 没有回答我关于字体的问题。
我尝试了以下方法:
DataGridViewRow r = dataGridView.Rows[0];
r.Cells[1].Style.BackColor = Color.Red;
我也试过了:
DataGridViewButtonColumn btnCOl = new DataGridViewButtonColumn();
btnCOl.FlatStyle = FlatStyle.Popup;
DataGridViewRow r = dataGridView.Rows[0];
r.Cells[1].Style = new DataGridViewCellStyle { BackColor = Color.LightBlue };
还是没用。
我也注释掉了这一行:
// Application.EnableVisualStyles();
如果有人知道如何更改 DataGridViewButtonColumn 中单个按钮的背景颜色,请提供帮助。
编辑: 我想为列中的单元格设置不同的颜色,例如有些是红色的,有些是绿色的。我不想为整列设置颜色。
【问题讨论】:
-
你可以简单地使用 btnCOl.Style.BackColor = Color.LightBlue;
标签: c# .net winforms datagridview datagridviewbuttoncolumn