[英]How to set style in for a column in DataGridView at design time
There's a question about changing cell background color in a DataGridView programatically有一个关于以编程方式更改 DataGridView 中的单元格背景颜色的问题
But is there any way to set the background color for a particular column using the WinForms Designer ?但是有没有办法使用 WinForms Designer为特定列设置背景颜色?
Right click the DataGridView and select Edit Columns右键单击 DataGridView 和 select 编辑列
Select the DefaultCellStyle Property and click on the Style Wizard Select DefaultCellStyle 属性并点击样式向导
In the CellStyle Builder window, you can set whatever properties you'd like, including BackColor
在 CellStyle Builder window 中,您可以设置任何您想要的属性,包括
BackColor
What this will do is set the property inside of the form.designer.cs file during InitializeComponent()
这将在
InitializeComponent()
期间设置form.designer.cs文件中的属性
private void InitializeComponent()
{
/// ...
this.ShadedColumn.DefaultCellStyle.BackColor = Color.Silver;
/// ...
}
* where this.ShadedColumn
is the name of the DataGridViewTextBoxColumn
control you added * 其中
this.ShadedColumn
是您添加的DataGridViewTextBoxColumn
控件的名称
Any code in InitializeComponent
will execute during the designer view, and technically you can update most styles directly here, but it's advised to use the GUI form builder to make any changes against this file InitializeComponent
中的任何代码都将在设计器视图期间执行,从技术上讲,您可以直接在此处更新大多数 styles,但建议使用 GUI 表单构建器对此文件进行任何更改
Further Reading : Set Default Cell Styles and Data Formats for the Windows Forms DataGridView Control Using the Designer进一步阅读: 使用设计器设置默认单元格 Styles 和 Windows Forms DataGridView 控件的数据格式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.