1 Reply Latest reply on Sep 19, 2011 9:48 AM by Flex harUI

    Datagrid columns widths

    archemedia Level 4

      Hi all,

       

      I have an urgent question concerning dataGrid column widhts.

       

      Here is a simplified code:

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

          layout="vertical" minWidth="955" minHeight="600" >

       

       

          <mx:Script>

              <![CDATA[

                  import mx.collections.ArrayCollection;

       

                  [Bindable] private var dp:ArrayCollection = new ArrayCollection(

                      [

                      {id: 1, label: "Item one"},

                      {id: 2, label: "Item two"}

                      ]);

       

                  public function init():void

                  {

       

                  }

       

              ]]>

          </mx:Script>

       

          <mx:DataGrid id="dg" height="100%" dataProvider="{dp}">

              <mx:columns>

                  <mx:DataGridColumn headerText="C1" width="200" dataField="label"/>

                  <mx:DataGridColumn headerText="C2">

                      <mx:itemRenderer>

                          <mx:Component>

                              <mx:HBox width="100%" horizontalScrollPolicy="off">

                                  <mx:Script>

                                      <![CDATA[

                                          import mx.controls.CheckBox;

       

                                          override public function set data(value:Object):void

                                          {

                                              super.data = value;

                                              for (var i:int = 0; i < 5; i++)

                                              {

                                                  var cb:CheckBox = new CheckBox();

                                                  cb.label = "cb" + i;

                                                  contentHolder.addChild(cb);

                                              }

                                          }

       

                                      ]]>

                                  </mx:Script>

                                  <mx:HBox id="contentHolder" width="100%" horizontalScrollPolicy="off"/>

                              </mx:HBox>

                          </mx:Component>

                      </mx:itemRenderer>

                  </mx:DataGridColumn>

              </mx:columns>

          </mx:DataGrid>

       

      </mx:Application>

       

      As you can see, within the set data functions, content is added to the itemRenderer. This is done AFTER the datagrid is initialized.

      Therefore, the column is not wide enough.

       

      I have two problems now:

       

      1. How can I calculate the widht of the contentHolder HBox?

      2. How can I redraw the datagrid's columns based on this calculated width?

       

      Any help much appreciated.

       

      Dany