I have a case where we are integrating some .NET controls with an old VB6 app. The VB app stores some user settings in the registry so that when the user changes column order/sizing in a grid, the app remembers.
In the .NET control i'm using the new wingrid, however there was a very strange behavior i encountered. My column was default Hidden. In the Initialize_layout event, i grab the width setting from the registry, set the column width on this hidden column, and then later in a different method set the Hidden property to false.
The effect was that from the time i set the width to the time the grid shows on the screen, the width has been increased. If the form is closed and subsequently opened, the column will continue to grow. I was able to negate this behavior by setting the column to visible default, but i still don't understand what was going on. Is this possibly a bug or is there something that happens with the siziing on hidden columns that i do not understand?
Hi Jason,
It's hard to know for sure without seeing the behavior. But here are a few wild guesses. :)
1) You are using AutoFitStyle or AutoFit on the DisplayLayout.If you are using AutoFit, then hiding and showing a column will change the size of that column because when you hide the the column, the other columns resize proportionally and thus become bigger than the hidden column. When you then show the column, it is now proportionally smaller than the other columns which were not hidden.
2) Using the DotNet grid in VB6 is not something we test or actively support. So this could be an issue with the environment.
If definately had something to do with the AutoFitStyle property. I turned it off and the issue went away.
With that said, i'm still not exactly sure what the sequence of hiding/resizing/unhiding was causing the weird behavior, but I've been able to workaround the issue.
Let's take a simple case... suppose I have a grid with 3 columns and AutoFitStyle is set to ResizeAllColumns.
To keep this example simple, let's say that the width available for the columns in the grid is 300 pixels. Each column sizes to 100 pixels wide.
Now I hide one of the columns.
The hidden columns width stays at 100, but the other two (visible) columns now split the available width of the grid. So the width of each is set to 150.
Now I show the hidden column. At this point, there are 3 columns visible and the widths of those 3 columns are 150, 150, and 100 for a total of 400 pixels. Since this is bigger than available width (300), each column has to be made smaller.
But the columns are resized proportionally. The total width of the columns goes over by exactly 100 pixels, so each column is sized 33 1/3 pixels smaller, leaving the new widths at 116, 116, and 66.
And that's how it happens. :)
Ahh! You da man!
I figured it was something like that, thanks for the explanation!