473,233 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,233 developers and data experts.

Make all the rows height even in DataGridView in .Net 2.0

99
This article explains how to make all the rows height the same in DataGridView in .Net 2.0 while using AutoSizeRowMode

In DataGridView 2.0,there is a option to resize row to fit the content of the cell.This will increase the row height.
Expand|Select|Wrap|Line Numbers
  1. this.dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCells;
But the row heights will not be the same through out the DataGridView (some row's height will be smaller than another row's height )

To make all of the rows in your DataGridView appear the same size, take the following the steps to set the max row height and set it to be the height for all the rows in dataGridView:
Step 1:
Find out the maximum row height and set the height to DataGridView preferred rowheight
Expand|Select|Wrap|Line Numbers
  1. void dataGridView1_RowHeightChanged(object sender, DataGridViewRowEventArgs e)
  2.       {
  3.  
  4.          int rowHeight = e.Row.Height;
  5.          if (this.dataGridView1.RowTemplate.Height < rowHeight)
  6.          {
  7.             this.dataGridView1.RowTemplate.Height = rowHeight;
  8.  
  9.          }
  10.     }
  11.  
Step 2
Set the AutoSizeRowsMode to none,then apply the maximum row height to all the rows
Expand|Select|Wrap|Line Numbers
  1.   private void dgLocation_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
  2.       {
  3.          int rowHeight=this.dataGridView1.RowTemplate.Height;
  4.  
  5.          this.dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
  6.          int numRows = this.dataGridView1.Rows.Count;
  7.          for (int i = 0; i < numRows; i++)
  8.          {
  9.             this.dataGridView1.Rows[i].Height = rowHeight;
  10.  
  11.          }
  12.  
  13.       }
  14.  
Jun 7 '07 #1
4 19673
How do you call these methods in a windows form?
Aug 17 '07 #2
Vidhura
99
These are the datagridview events.

this.dataGridView1.RowHeightChanged += new System.Windows.Forms.DataGridViewRowEventHandler(t his.dataGridView1_RowHeightChanged);

this.dataGridView1.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEvent Handler(dataGridView1_RowPostPaint);
Nov 27 '07 #3
how we connect a database to datagrid view in vb.net language??
Mar 14 '08 #4
I would suggest to change RowPostPaint in following way:
Expand|Select|Wrap|Line Numbers
  1. this.dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
  2. foreach (DataGridViewRow row in dataGridView1.Rows)
  3.    if (row.Height != rowHeight) row.Height = rowHeight;
  4.  
Apr 14 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
by: Luca Beretta | last post by:
I think this a simple question but i'm breaking my brain without results. I've a datagridview bounded to a datatable, with an imagecolumn that should contain a different bitmap depending from a...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
0
by: romancoelho | last post by:
Hey everyone, I know this has to be simple, but can't figure out how to do it. How can I display the grid lines in all rows in the gird. The default behavior of the DataGridView seems to be that it...
4
by: lord.zoltar | last post by:
I am wondering how you guys highlight cells or rows (by changing the text or background colour) in a DataGridView. Right now, I apply styles to certain rows or cells in the CellFormatting even...
4
by: craig.wenger | last post by:
I am using a DataGridView to display information stored in classes. I am linking to the information with the Tag property of the DataGridView rows. Unfortunately, whenever I set the Tag property,...
5
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I want to be able to increase or decrease row heights of a populated DataGridView from the keyboard. I set up a test program with menu items to increase and decrease, assigned shortkey keys...
5
by: bill | last post by:
When you retrieve records to diplay in a DataGridView control the first record has the background highlighted even though no row is yet selected. Does anyone know a way to suppress this first...
6
by: Gun Slinger | last post by:
Hi guys, I have a quick question which i have pondered for a little while. I'm not sure if its even a good idea (so maybe advice on whether or not to do it would be helpful as well). I want to...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.