In my grid I had following line of code which disabled user's manual resizing:
dgvTruckAvail.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
Now I needed to set column height in code and it didn't work (see DataGridView setting row height doesn't work)
I figured that it was this line of code that caused non-sizing issue. However, now I need to figure out how to
and
Any pointers?
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
.
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.
In the properties window set:
AllowUserToResizeRows = False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With