This content has been marked as final. Show 3 replies
I have been battling with this issue for quite some time now...
I have tried the following:
1) try resizing
2) catch TypeError (if thrown)
3) try using DataGrid.commitProperties()
4) try resizing again.
Unfortunately these steps help sometimes. Still a race condition problem it seems.
Has anyone found a solution to this?
The problem is: If a column was not previously visible and you need to set the width of that column (even after setting column.visible=true) flex will throw this exception because the column is not yet in the visibleColumns array of data grid.
I vaguely remember getting round this problem by setting up different DataGrids each with its own set of visible columns and each on its own layer of a ViewStack. By applying the underlying array to each DataGrid thus: dgn.dataProvider = array.slice(); you can still manipulate each dataProvider's array without affecting them all.
Now you can simply switch the ViewStack layer instead of changing the list of visible columns.
One of the things that makes Flex so incredibly versatile and ultimately such a fantastic tool is its ability to get round problems since there are always so many different ways to effectively do the same thing. You just have to think creatively.
Thanks, I'll try out different approaches. I have already considered many ways of forcing the DataGrid to update it's visible columns. I am going to do some heavy debugging and determine the right path. I am also trying to minimize memory usage so using multiple data grids can become problametic. However I see your point. Also what might work nicely is for the task i want to do (restore to defaults) I might wind up cloning all the columns and just swapping the data grid's entire columns array with a new one instead of trying to apply default preferences. (This is a data grid that remember's it's state).
In any case, thanks for the advice.