【发布时间】:2016-09-08 23:02:03
【问题描述】:
我有一个DataGridViewRow,我以编程方式将其添加到DataGridView“表”中。我希望其中一个单元格是DataGridViewButtonCell,以便我可以单击它。 (我意识到我可以在 on_click 的 datagridview 上有一个处理程序,但为了代码的简单性,我想保持这种方式)。
我希望能够设置 DataGridViewButtonCell 的前景色/背景色。
DataGridViewRow dgvRow = new DataGridViewRow();
dgvRow = (DataGridViewRow)dgv.Rows[0].Clone();
dgvRow.Cells[0].Value = filename;
dgvRow.Cells[0].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
DataGridViewButtonCell dgvBtn = new DataGridViewButtonCell();
dgvRow.Cells[1].Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
dgvBtn.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
dgvBtn.Style.BackColor = Color.Green; //this sets the color of the cell, not the button in the cell.
问:如何设置单元格中出现的按钮颜色?
【问题讨论】:
标签: c# button datagridview background-color