Folks,Again with a hierarchical grid. When I set the Width and MaxWidth for a Column at design-time both are completely ignored when I bind to a datasource with a child band. Bind to a source with no children and it works fine.
The weirdness here is that only the parent row is affected. The settings are not ignored on the child row - i.e. the column adheres to the width and maxwidth setting!
What's the story with this - really don't want to have to code column width when that's what the designer is supposed to be for. Kind of annoying that even the MaxWidth is ignored.
Thanks for any pointers.
Whether the row is expanded or not should not matter as long as you call PerformAutoResize and pass in AllRowsInBand.
One thing that might be happening is that your bands are synchronizing the column widths. By default, all of the columns in the grid line up in every band. So if you are calling PerformAutoResize on a column in the parent band, and then you call it again on the child band, the parent band's setting will be lost in favor of the child band.
Try setting AllowColSizing to Free and that should fix that.
Another option you might want to think about is using the CalculateAutoResizeWidth method of the column. This method allows you to get the size that the grid would use to auto-size the column, but doesn't actually apply it. That way you could get the value, check it against your min/max and then just set the Width on the column.
Well my goal is to size the columns to always fit their contents but within a min and max width. I want to have a nice presentable view but if a number/piece of data comes in that needs the cell expanded I want that to happen automatically for the column.
I have tried every combination of PerformAutoResize and, for test purposes, from the InitializeRow so there will definitely be data there. Could it be to do with some calculation involving the + expansion sign on each new child row?
Using the lastest version available for my environment: 7.3.20073.1056
If you just want the columns to size to their contents, then you are definately much better off doing it at run-time in the InitializeLayout event. If it's not working, then my guess is that you are passing on the wrong params to the PerformAutoResize method. You need to make sure you pass in the right params. By default, it will only size the currently loaded and visible rows - and there won't be any when the InitializeLayout event fires.
I'm not sure why the design-time column settings aren't being maintained from design-time, though. That should work if you are using a data source that exists at both design-time and run-time. Unless it's a bug. Are you using an old version of the grid?
Hi Mike. No, I'm using a BindingSource object at design-time. Only diff at run-time is that it is populated with data! If I call PerformAutoResize on the column at band zero it returns the correct value but even putting that in the InitializeRow doesn't work - somewhere between InitializeRow and my return to my code xyzBindingSource.DataSource = .... it gets set again.
It sounds to me like the data source you are binding to t run-time is not matching the exact data structure you have set up at design-time. In that case, everything is blown away and the grid creates a new layout to match the data structure. If any of the columns don't match or the band names of any of the bands don't match, you will lost the layout when you bind at run-time, because the grid has to assume it's a totally new structure.
So how are you setting up your design-time structure in the grid? Are you using the designer to add the bands and columns? Or are you binding to the same data source at design-time that you will be using at run-time?
You might want to check out this KB article:
HOWTO:How can I define columns in the grid at Design-time and bind them at run-time so that some fields of the data are excluded from the grid?