【问题标题】:DataGridView setting row height doesn't workDataGridView 设置行高不起作用
【发布时间】:2012-01-02 21:04:02
【问题描述】:

尝试像这样设置 RowHeight(在代码中):

dgvTruckAvail.RowTemplate.Height = 48;

不起作用。我还尝试设置我添加的每个列的高度 - 不起作用。

这里是网格属性:

this.dgvTruckAvail.AllowUserToAddRows = false;
this.dgvTruckAvail.AllowUserToDeleteRows = false;
this.dgvTruckAvail.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
    | System.Windows.Forms.AnchorStyles.Left) 
    | System.Windows.Forms.AnchorStyles.Right)));
this.dgvTruckAvail.BackgroundColor = System.Drawing.Color.White;
this.dgvTruckAvail.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.dgvTruckAvail.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
this.dgvTruckAvail.Columns.AddRange(
    new System.Windows.Forms.DataGridViewColumn[] 
    {
        this.colMon,
        this.colTue,
        this.colWED,
        this.colThu,
        this.colFri,
        this.colSat,
        this.colSun});
this.dgvTruckAvail.Cursor = System.Windows.Forms.Cursors.Default;
dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle8.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle8.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle8.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle8.SelectionBackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle8.SelectionForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle8.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.dgvTruckAvail.DefaultCellStyle = dataGridViewCellStyle8;
this.dgvTruckAvail.EnableHeadersVisualStyles = false;
this.dgvTruckAvail.Location = new System.Drawing.Point(0, 22);
this.dgvTruckAvail.Margin = new System.Windows.Forms.Padding(4);
this.dgvTruckAvail.Name = "dgvTruckAvail";
this.dgvTruckAvail.ReadOnly = true;
this.dgvTruckAvail.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
this.dgvTruckAvail.RowTemplate.Height = 48;
this.dgvTruckAvail.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.dgvTruckAvail.ShowCellToolTips = false;
this.dgvTruckAvail.Size = new System.Drawing.Size(1098, 394);
this.dgvTruckAvail.TabIndex = 0;

我不是在填充网格。手动添加的行和手动填充的单元格。 您对我还可以尝试设置什么有什么建议吗?也许以某种方式覆盖 Grid 本身?

【问题讨论】:

    标签: c# winforms datagridview


    【解决方案1】:

    两个想法:

    1) 在绑定 DGV 之前设置 RowTemplate.Height

    2) 设置 AutoSizeRowsMo​​de = none

    这些中的一个或两个都可能有帮助。

    【讨论】:

      【解决方案2】:

      设置每个Height属性确实有效。

      foreach (DataGridViewRow row in dataGridView1.Rows)
      {
          row.Height = 80;
      }
      

      【讨论】:

      • 你说得对。请参阅我的另一个问题(我发现它为什么对我不起作用)stackoverflow.com/questions/8705640/…
      • 必须在“DataGridView.Visible”属性设置为“true”后设置row.Height。为“DataGridView.VisibleChanged”事件编写一个事件处理程序,因此当“Visible == true”时,设置每一行的“高度”。
      • 这样更高效:dg.RowTemplate.Height = 30;
      • 这对我来说很完美! @LucaZiegler 该选项对我不起作用,我不知道为什么!我已经浏览了所有的代码,什么都没有。
      【解决方案3】:

      AutoSizeRowsMode 属性从无更改为 AllCells 或任何其他值。

      【讨论】:

        【解决方案4】:

        AutoSizeRowsMo​​de 设置为 AllCells

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2011-10-31
          • 2011-09-21
          • 2016-04-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多