4 Replies Latest reply on Mar 1, 2007 10:10 AM by dimival

    Obtaining a DataGridColumn real width

    dimival Level 1
      I have a DataGrid with two columns, the normal behavior of the DataGrid is to set the columns width to fit its display area. So, even though a DataGridColumn is larger than its default width (100) if i try to obtain its width it keeps saying that is 100, which is not actually true.

      So any idea of how to obtain the real width of a DatagridColumn???
        • 1. Re: Obtaining a DataGridColumn real width
          michael_ramirez44 Level 1
          The documentation states:

          The width of the column, in pixels. If the DataGrid's horizontalScrollPolicy is false all visible columns must fit in the displayable area and the DataGrid will not always honor the width of the columns if the total width of the columns is too small or too large.

          If you need to know what the width of a column is you probably need to set the horizontalScrollPolicy to "on" and specify an column width.
          • 2. Re: Obtaining a DataGridColumn real width
            dimival Level 1
            I already know what the documentation states, that's why i am posting here.........

            I don't need to specify a column's width, i want the DataGrid to automatically do that, to make all visible columns fit in the displayable area. That's fine, that works for me, BUT when this happens, all columns width property remain with a 100 value.

            I don't know if i am explaining it correctly, but the point is that the DataGrid is obviously making the columns larger than 100 pixels, and that is fine, perfectly fine, what is wrong is that the column's width property is not being refreshed, so it remains as 100 pixels when obviously it is not.

            So, what i need is to be able to get a column's real width after the DataGrid has made all the columns fit.
            • 3. Re: Obtaining a DataGridColumn real width
              jfillman Level 1
              For the DataGrid, use the creationComplete event. Give the column(s) you want an id and then in the function do this:
              <mx:DataGrid id="testGrid" creationComplete="testFunction()">
              <mx:DataGridColumn headerText="Column 1" id="columnOne">
              <mx:DataGridColumn headerText="Column 2" id="columnTwo">


              public function testFunction():void

              The Alert will show you the width of the column one.
              • 4. Re: Obtaining a DataGridColumn real width
                dimival Level 1
                That worked perfectly!!! thanks jfillman

                I did this to try it out:

                <mx:DataGrid width="100%" creationComplete="test()">
                <mx:DataGridColumn id="uno" headerText="UNO"/>
                <mx:DataGridColumn id="dos" headerText="DOS"/>
                <mx:DataGridColumn id="tres" headerText="TRES"/>
                <mx:Label id="test1" text="{uno.width.toString()}"/>
                <mx:Label id="test2 />
                import mx.controls.Alert;
                public function test() : void
                test2text = uno.width.toString();

                The output is :
                test1 : 100
                test2 : 93.333 (this depends on the application width so this is an example)

                The funny thing is that both labels display the column's width, but test1 is always 100 while test2 does show the real width

                Could it be a bug?

                Thanks again jfillman