【问题标题】:How to set style in for a column in DataGridView at design time如何在设计时为 DataGridView 中的列设置样式
【发布时间】:2019-11-14 17:08:19
【问题描述】:

关于changing cell background color in a DataGridView 编程的问题

但是有没有办法为特定列设置背景颜色使用 WinForms 设计器

【问题讨论】:

    标签: c# .net winforms datagridview


    【解决方案1】:
    1. 右键单击 DataGridView 并选择编辑列

    2. 选择 DefaultCellStyle 属性并单击样式向导

    3. 在 CellStyle Builder 窗口中,您可以设置任何您喜欢的属性,包括 BackColor

    这将在InitializeComponent()

    期间设置form.designer.cs文件内的属性
    private void InitializeComponent()
    {
        /// ...
        this.ShadedColumn.DefaultCellStyle.BackColor = Color.Silver;
        /// ...
    }
    

    * 其中 this.ShadedColumn 是您添加的 DataGridViewTextBoxColumn 控件的名称

    InitializeComponent 中的任何代码都将在设计器视图期间执行,从技术上讲,您可以直接在此处更新大多数样式,但建议使用 GUI 表单构建器对此文件进行任何更改

    延伸阅读Set Default Cell Styles and Data Formats for the Windows Forms DataGridView Control Using the Designer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 2015-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-29
      相关资源
      最近更新 更多