I need to resize rows in a grid based on a single columns value. The xRow.PerformAutoSize() method seems to be sizing rows based on the longest text in any column (even if not visible). Is there a way to control this.
Example:
Column A has description
Column B has street address
I want to expand the row size to allow the entire Description to display on a row by row basis. Rows where the Description is blank still resize with .performautosize because the street address does not fit in the cell. I want to ignore the street address in this case.
Thanks in advance for any help or direction.
Awesome...that works for me. Feels good that it was not something obvious that I spent days trying to resolve. These workarounds you offer are great - my code is cluttered anyway so the above fix works. Also like having the option of leaving scrollbar and will keep that in my back pocket.
I appreciate your diligence and staying on top of this through resolution. You are a great company, with great products and great people. Thanks again.
Hi Bob,
I've been looking into this issue and it's actually much more complicated than it seems.
This is actually not a new issue. I went all the way back to NetAdvantage v8.1 and it was happening all the way back then and probably before. This begs the question of why no one ever noticed it before. The answer is that the issue only happens under some very specific and rare circumstances with a very specific combination of properties.
It doesn't necessarily occur when there is extra space for more rows in the grid. If you change your sample so that there are only 4 rows instead of 5, the problem does not occur. In fact, the problem does not occur with 1, 2, or 3 rows, either.
The issue actually occurs when autosizing a row causes that row to increase in size such that the grid needs a vertical scrollbar where it did not need one before. Presumably, it also happens if autosizing a row would remove the vertical scrollbar, as well, but I did not confirm that.
You can demonstrate this another way by running your sample and then double-clicking on the bottom edge of each row one at a time from top to bottom. The first 4 rows work fine because even when autosized, they fit within the visible area of the grid. But when you resize row 5, it crosses the bottom edge of the grid which means that the grid now needs a vertical scrollbar and all of the rows are re-initialized to their original height.
So the next question is... why does the grid need to re-initialize the rows in this case. And the answer is because you have set the AutoFitStyle property. Since you are using AutoFitStyle, the existence of a vertical scrollbar changes the width of the columns and when this happens, the grid has to re-initialize certain metrics. I won't go into details on why it needs to do that, because that gets REALLY complicated. :)
Anyway... I don't think there is anything we can do about this. The grid cannot know, in this case, that the metrics should not be re-initalized. It's a sort've catch-22 that it has to adjust the column widths and this causes the row heights to change.
The good news is that there are several very easy things you can do to get around it. The workaround I gave you above works because you are manually setting the height of the row. The row keeps track of this and it knows not to re-initialize itself later on. But that code is something of an ugly hack and you probably don't want it cluttering up your code.
The first and simplest recommendation I have for you is that you set RowSizing on the grid to AutoFree instead of Free. I suspect this is what you really want, anyway, since you are autosizing the rows in code. You probably didn't realize that this setting is better for what you want. Using AutoFree means that when the metrics are re-initialized, the rows are re-autosized and so it all works correctly.
If, for some reason, you must use Free instead of AutoFree, then another way to avoid this issue is to force the vertical scrollbar to display all the time.
Me.gridData.DisplayLayout.Scrollbars = Scrollbars.Vertical
This way, the grid never gets into a case where it has to recalculate the columns widths and to the row heights are not affected.
Hello BobRayes,
I have created the following case for you: CAS-102822-C1S9D3
We could continue our conversation through it.
Thank you for contacting us.
Thanks. This helps both the developer support and the workaround. As for the second test, just group by Name and then hit button 1 or 3 (they are the same) and expand the group by row. May be the same bug in that the group by causes the visible rows to be compressed smaller than the available hit as in the bug you noted.
BTW... I found a workaround:
Private Sub Resize_Click(sender As System.Object, e As System.EventArgs) Handles Resize.Click, ResizeAgain.Click, ResizeNotes.Click For Each rowTemp As UltraGridRow In gridData.Rows.GetFilteredInNonGroupByRows rowTemp.PerformAutoSize() rowTemp.Height += 1 rowTemp.Height -= 1 Next End Sub