DataGridView setting Row height in code and disable manual resize

In the properties window set:

AllowUserToResizeRows = False


Setting row size is a real challenge. Check how many gripes and responses there are on the web. I've found that sometimes one way works and other times it no longer works.

Do this: Place a DataGridView on your form. Edit and add several columns. It doesn't matter what they are because you'll discard this DGV in a moment. Go into this DataGridView's properties and edit RowTemplate/Height to something small or large (only so you can see it working). Add a line of code in your method to set XXX.RowCount to something like 12 just to populate this test DataGridView. Run your code to verify the row height has changed.

Open the XXX.Designer.cs code. Expand the "Windows Form Designer generated code" and look for code that applies to what you just did with DataGridView. Copy it all into the method where you are trying to adjust/set row height. Comment out all of your code. Line by line, modify the self-generated code to use your object's name. Test repeatedly for any failure and isolate it at that time.

Now go back and delete this test DataGridView object.


Set:

dgvTruckAvail.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
dgvTruckAvail.AllowUserToResizeRows = false;

This will disable row autosizing and manual row resizing. To set the row height you can use the Height and MinimumHeight properties of the RowTemplate.