Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGridView setting row height doesn't work

Trying to set RowHeight like this(in code):

dgvTruckAvail.RowTemplate.Height = 48;

Doesnt' work. I also tried to set Height of every colum I add - doesn't work.

Here is grid properties:

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;

I'm not binging grid to populate. Rows added manually and cells populated manually. Do you have any suggestions on what else I can try to set it? Maybe override Grid itself somehow?

like image 517
katit Avatar asked Jan 02 '12 21:01

katit


3 Answers

Two ideas:

1) Set RowTemplate.Height before you bind the DGV

2) Set AutoSizeRowsMode = none

Either or both of these might help.

like image 198
nycdan Avatar answered Oct 24 '22 22:10

nycdan


Setting the Height property of each Row does work.

foreach (DataGridViewRow row in dataGridView1.Rows)
{
    row.Height = 80;
}
like image 33
tafa Avatar answered Oct 24 '22 22:10

tafa


AutoSizeRowsMode property change from none to AllCells or to any other value.

like image 32
OldTrain Avatar answered Oct 24 '22 23:10

OldTrain