Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent VFP from resizing Grid Column widths as per data in the column 1

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
549
MU
Hi friends,

I have a grid and I have set specific widths for columns.
When I set the font size for the grid (and columns) to some bigger font size (currently Arial Narrow 14), upon display of grid, the columns are resized which appears that the sizes are as per the data of the columns.

How we can prevent vfp from auto resizing grid column widths?

For additional info,
AllowHeaderSizing of grid is .F.
AllowAutoColumnFit of grid is 2 (do not allow auto resize)
Resizable property of all columns are .F.

Any idea ?

Thanks
Rajesh
 
Your settings are clearly not allowing manual autofitting of columns,

but something does. And you need to look for code doing it, not properties preventing it, because all the properties prevent is manually doing it, not programmatically.
You will find code doing grid.AutoFit, because that's what you're describing. And AutoFit will work, no matter how these properties are set. One way this could sneak up on you is when there is a fontsize_assign method that does AutoFit after setting the fontsize.

If you don't want AutoFit() to work, then don't call it and don't let class code call it.

Chriss
 
Chriss,

I added a wait window inside the grid.AutoFit method. But I don't see anything.
Let me try to figure out from where else this auto sizing could be triggering

Rajesh
 
Mike,

Let me try that.

Btw, I missed to mention that the grid is in a container. The container which has many other controls is actually a class.
Interestingly, the grid columns are not even resized to the sizes saved in the grid in class.

Rajesh
 
Oh,

so maybe someone programmed an autofit feature before VFP had it. I know some resizer frameworks do that, they also act on grids, if you let them. Usually they will only change width to relative same percentages if a form is resized or the container they maintain. But someone may have dug as deep as using form.textwidth or the TXTWIDTH() function to establish the autofit behavior.

Mikes tip likely works, you could get a breakpoint to work on changes of column widths. I guess though AutoFit actually does effectively change widths it would still be under the radar. Just like maximising a form obviously visible changes the form width to display width, but doesn't change the form.width property value itself. I'm sure about the latter, not the former, but expect to be surprised.

Chriss
 
One more thing to look out for would also be Anchor.

I know anchor actually stops to work within grids, you don't have Anchor as a column property that would cause them to anchor to the overall grid size, and anchoring of textboxes you make grid column controls don't work with the column or grid as parent container reference.

Column1.text1.widht changes don't apply, as the column control is autosized to the column width and grid.rowheight determines the inner control height, so make a breakpoint watch over column.width only, don't wait for the inner control size properties to change.

Chriss
 
Chriss,

The class that I mentioned is also a part of our software. I have full access to the class code. I checked but couldn't find anything to do with this behaviour. It doesn't have any Resize code or use any 3rd party resize class.

Rajesh
 
Well,

but if you make a breakpoint not at some place in code but with the condition that a column.width changes, then you'll see what code does change it.

That was suggested by Mike and I second it.

Create a conditional breakpoint with the breakpoints utility dialog:
conditional_breakpoint_sotxef.png


Adjust to your needs and your form.

Chriss
 
Chriss,

Scenario once again (only for more clarity and additional info).

My Form
-> Container1 (based on a class which has grid with 5 columns, buttons etc)
(the baseclass 1st column width is 137, the control is comboBox)
(in my form I changed the width of 1st column of grid to 208)

-> Container2 (based on the same above class)
(in my form I changed the width of 1st column of grid in this also to 208)

Then, in the INIT of Container1 grid, I gave a wait window for 1st column width.
Strangely, it shows 164!
This means, the breakpoint (as you suggested) didn't fire because the width was already changed in Init and then there was no subsequent change to width.

Now, I will explicitly change the columns widths in the form Init. That should work I hope. But, if the change the grid design, I have to change the Init code also.

Rajesh
 
Rajesh, thanks for clarifying there was no change registered.

There should be, the breakpoint is active even before the form starts.
Are you sure you edit the form on the class level that is actually used? For example, if you change the base class form but there is a child class that overrides size properties, those are the default, no matter what you change in the base class, and their "change" isn't registered as a width change, as it's the override of the initial width of a higher level class.

Chriss
 
In short: Basic class inheritance of a hierarchy of baseclass, childclass1, childclass2. If you change baseclass.width, that will be inherited, but only as long as neither childclass2 or childclass1 override the width on their level, i.e. their value is not at the inherited default value. Changing the base class doesn't affect the inherited value, in such cases.

So everything you want the base class to control can't be overridden in child classes or you cut off the inheritance.

Chriss
 
Chriss,

I am not making the size changes in the parent class.
Parent class is intact. My point was, the size the column has after INIT of the form, is neither the width in the parent class nor the width I gave at design time (in the grid in the child class). I tried changing the content of the comboBox in the 1st column, which is the only control in that column.

To test, I added another grid (which is from the vfp base class and not from our vcx) and set the column widths the same as the grid which shows problem. Also, set the content of the 1st column the same. But, the 2nd grid didn't make any changes to the width. Really don't understand where and what I am missing to catch or understand.

For time being, as it's urgent, I will explicitly set the column widths in the form INIT.
However, I will investigate this further.

Rajesh
 
I don't know how that should work, the only other thing that would change the width without code doing it and without it registered as a change a breakpoint would catch might be grid reconstruction.

How do you set the recordsource? Already at design time? And is the recordsource cursor existing at grid init (which comes before form init, just to state one common source of error to generate the grid data in form init, when the grid already had its init and might have reconstructed already).

Edit: No, forget that cause, I just did a for where the grid intentionally reconstructs by creating a grid cursor too lat and assigning it to grid recordsource. In this experiment the breakpoint did getactive.

Chriss
 
Ah, but the point is not just defining the breakpoint, also have the debugger started before starting the form.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top