dataGridViewButtonColumn格式不正确 [英] dataGridViewButtonColumn not formatting correctly
问题描述
我正在使用C#WinForm.我正在尝试格式化DataGridViewButtonColumn
,但是此代码未设置Text
属性或设置BackColor
和ForeColor
.代码如下:
I''m using C# WinForm. I''m trying to format my DataGridViewButtonColumn
but this code is not setting the Text
property or setting the BackColor
and ForeColor
. Here''s the code:
private void Form1_Load(object sender, EventArgs e)
{
DataGridViewButtonColumn btnStop = new DataGridViewButtonColumn();
btnStop.Name = "btnStop";
btnStop.Text = "STOP";
btnStop.HeaderText = "Stop";
btnStop.UseColumnTextForButtonValue = true;
btnStop.CellTemplate.Style.ForeColor = Color.Red;
btnStop.CellTemplate.Style.BackColor = Color.White;
dgvDisplay.Columns.Add(btnStop);
}
这开始变得非常愚蠢!我将FlatStyle
属性设置为"Popup
",并且现在已设置BackColor
,但是在所有其他FlatStyle
项下BackColor
都不会设置,只有按钮周围的边框会改变颜色和Text
仍不显示.
This is starting to get very silly! I set the FlatStyle
property to "Popup
" and the BackColor
is now being set, but under all other FlatStyle
''s the BackColor
won''t set, only the border around the button changes color and Text
is still not displaying.
Anyone out there know how to set these properties?
推荐答案
您是否已向DataGridView
添加任何行?
在DataGridView
中显示的新行中(在左侧边框中带有 * ),用于向DataGridView
添加行,该按钮将不显示文本,因为Button
是在那里不起作用.在DataGridView
中添加一行后,在添加的行中Button
会正确显示Text
和其他属性.
Have you added any rows to yourDataGridView
?
In the new row displayed in theDataGridView
(with an * in the left border), for adding rows to theDataGridView
, the button will not display the text, as theButton
is not functional there. Once you add a row to theDataGridView
, in the added row theButton
displaysText
and other attributes properly.
这篇关于dataGridViewButtonColumn格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!