grid row hight

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi all

Is there more effective way to change height of all rows
in a DataGridView at once instead of going through all rows and setting

row.height=a

for each row?

thank you
Alex
 
Alex said:
hi all

Is there more effective way to change height of all rows
in a DataGridView at once instead of going through all rows and setting

row.height=a

for each row?

Yes, there is a RowTemplate property of the DataGridView that will be
used to create new rows. Simply set the height property of it.

Example follows.

Chris.


using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace ProofOfConcept
{
public class Form1 : Form
{
public Form1()
{
InitializeComponent();

dataGridView1.RowTemplate.Height =
dataGridView1.RowTemplate.Height * 4;

dataGridView1.Columns.Add("Test1", "Column");
dataGridView1.Rows.Add("Smith");
dataGridView1.Rows.Add("Jones");
}

/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
private DataGridView dataGridView1;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();

((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.Location = new System.Drawing.Point(0, 0);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(251, 238);
this.dataGridView1.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(251, 238);
this.Controls.Add(this.dataGridView1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);

}
#endregion
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top