C# DataGridView设置行高不需要';行不通
正在尝试这样设置行高(在代码中): 不起作用。我还试着设置我添加的每一个柱的高度——不起作用 以下是栅格属性:C# DataGridView设置行高不需要';行不通,c#,winforms,datagridview,C#,Winforms,Datagridview,正在尝试这样设置行高(在代码中): 不起作用。我还试着设置我添加的每一个柱的高度——不起作用 以下是栅格属性: this.dgvTruckAvail.AllowUserToAddRows = false; this.dgvTruckAvail.AllowUserToDeleteRows = false; this.dgvTruckAvail.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorSt
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;
我并不是为了填充网格。手动添加行,手动填充单元格。
你对我还能做些什么有什么建议吗?也许会以某种方式覆盖网格本身?两个想法:
1) 在绑定DGV之前设置RowTemplate.Height
2) 设置AutoSizeRowsMode=none
这两个选项中的一个或两个都有帮助。设置每一行的
高度属性确实有效
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Height = 80;
}
属性从“无”更改为AllCells
或任何其他值。将AutoSizeRowsMode设置为AllCells。请参阅我的另一个问题(我发现了为什么它对我不起作用),您必须将“DataGridView.Visible”属性后的row.Height设置为“true”。为“DataGridView.VisibleChanged”事件编写事件处理程序,以便在“Visible==true”时设置每行的“高度”。这样更有效:dg.RowTemplate.Height=30;这对我来说太完美了@卢卡齐格勒:这个选择对我不起作用,我也不知道为什么!我已经看过所有的代码了,什么都没有。
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Height = 80;
}