grid row hight

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QWxleCBLLg==?=

    #1

    grid row hight

    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
  • Chris Shepherd

    #2
    Re: grid row hight

    Alex K. wrote:
    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()
    {
    InitializeCompo nent();

    dataGridView1.R owTemplate.Heig ht =
    dataGridView1.R owTemplate.Heig ht * 4;

    dataGridView1.C olumns.Add("Tes t1", "Column");
    dataGridView1.R ows.Add("Smith" );
    dataGridView1.R ows.Add("Jones" );
    }

    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.Componen tModel.IContain er 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.Disp ose();
    }
    base.Dispose(di sposing);
    }

    #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 InitializeCompo nent()
    {
    this.dataGridVi ew1 = new System.Windows. Forms.DataGridV iew();

    ((System.Compon entModel.ISuppo rtInitialize)(t his.dataGridVie w1)).BeginInit( );
    this.SuspendLay out();
    //
    // dataGridView1
    //
    this.dataGridVi ew1.ColumnHeade rsHeightSizeMod e =
    System.Windows. Forms.DataGridV iewColumnHeader sHeightSizeMode .AutoSize;
    this.dataGridVi ew1.Dock = System.Windows. Forms.DockStyle .Fill;
    this.dataGridVi ew1.Location = new System.Drawing. Point(0, 0);
    this.dataGridVi ew1.Name = "dataGridView1" ;
    this.dataGridVi ew1.Size = new System.Drawing. Size(251, 238);
    this.dataGridVi ew1.TabIndex = 1;
    //
    // Form1
    //
    this.AutoScaleD imensions = new System.Drawing. SizeF(6F, 13F);
    this.AutoScaleM ode = System.Windows. Forms.AutoScale Mode.Font;
    this.ClientSize = new System.Drawing. Size(251, 238);
    this.Controls.A dd(this.dataGri dView1);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHan dler(this.Form1 _Load);

    ((System.Compon entModel.ISuppo rtInitialize)(t his.dataGridVie w1)).EndInit();
    this.ResumeLayo ut(false);

    }
    #endregion
    }
    }

    Comment

    Working...