dataGridViewButtonColumn格式不正确 [英] dataGridViewButtonColumn not formatting correctly

查看:98
本文介绍了dataGridViewButtonColumn格式不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#WinForm.我正在尝试格式化DataGridViewButtonColumn ,但是此代码未设置Text 属性或设置BackColorForeColor.代码如下:

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 your DataGridView?
In the new row displayed in the DataGridView (with an * in the left border), for adding rows to the DataGridView, the button will not display the text, as the Button is not functional there. Once you add a row to the DataGridView, in the added row the Button displays Text and other attributes properly.


这篇关于dataGridViewButtonColumn格式不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆