DataGridView Row Height Autosize
Asked Answered
P

4

31

I am using a DataGridView in C# .NET 3.5 and I want the height of all rows set to AutoSize.

I set WrapMode = true but am still not getting the height to autosize.

Pecoraro answered 16/10, 2010 at 7:55 Comment(0)
K
60

DataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells

See http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.autosizerowsmode.aspx

Kumquat answered 21/10, 2010 at 21:4 Comment(1)
Thanks @Kumquat +1. You can also set the properties of the grid at design time using the same properties.Barometry
M
5

if you want to change only for particular row :

 int j = Rowindex;
 datagridview1.AutoResizeRow(j, DataGridViewAutoSizeRowMode.AllCells);
Malacostracan answered 19/12, 2014 at 6:49 Comment(0)
E
2

DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;

is a better choice, if you want to keep same width of columns.

Eurydice answered 17/11, 2012 at 8:39 Comment(1)
As long as DataGridViewAutoSizeRowsMode does not have a definition for DisplayedCellsExceptHeaders it must be AllCellsExceptHeaders.Arsenal
F
0

Setting the "DefaultCellStyle" -> WrapMode = true in Design, easy!

Fredric answered 21/7, 2021 at 22:25 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.