It's very very frustrating. I am using a singleton class (popup, which means it doesn't forget the last used variables) which contains a datagrid. I am making various columns visible/invisible, setting the widths and headers in accordance to data received from a database call. Everything works fine except that when I put the breakpoints before and after the point where I change width of columns, I do not see the change in width of datagrid at all! Instead I see some values totally out of sync as widths of datagrid column! However, since it is a singleton class, the next time I call this popup,开发者_StackOverflow社区 I see widths which I did set up in last call.
I must be messing up in calling the setWidth() function (which is my custom function which changes the width of datagrid in action script). What should be the point where I should call this function? I tried in creationComplete, show and in the setter of dataprovider. Doesn't help...
I have kept horizontal scroll policy as 'off' (turning it on totally messes it up).
If I do datagrid.validateNow(), it doesn't help! And why the hell I don't see the width change reflected immediately if I put the breakpoints before and after the change. Somebody please advise me about what I am doing wrong here.
Thanks.
First of all you are indicating yourself what might be wrong here.
1) When you update the width when the component is visible => no change
2) When you close the popup and reopen this it is ok, this also means that the item has been re-rendered whereas it was not the first time. This means that you indeed have to try and trigger this yourself.
Here are some usefull links concerning flex component lifecycle. These should help you figure out which methods to call and / or override.
http://weblog.mrinalwadhwa.com/2009/06/21/flex-4-component-lifecycle/
http://www.slideshare.net/rjowen/adobe-flex-component-lifecycle-presentation
Furthermore, you should never call validateNow() directly, but use invalidation methods instead.
I guess in this case you need to trigger the measurement of your component so a call to invalidateSize() should do just fine.
Cheers
The key is to set the horizontalScrollPolicy="on" before you set the widths. See fixed row width in DataGrid quirk or Flex 3 DataGrid Column Width Problem
精彩评论