2 Replies Latest reply on Apr 27, 2009 10:49 PM by Madhav Subedi

    Retrieving top-left corner coordinates of a row in datagrid

    Mongolian Beef Level 1

      Hi,

       

      I need to know how to retrieve a row's top-left corner coordinates (x-y) from a datagrid when selected.  I can't seem to find the coordinates from datagrid or datagridcolumn.  Any help would be appreciated.  Thanks.

        • 1. Re: Retrieving top-left corner coordinates of a row in datagrid
          Gregory Lafrance Level 6

          DataGrid x y easy, DataGridColumn x y not so easy:

           

           

           

           

           

           

           

           

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

          <mx:Application

           

           

          xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

          >

           

           

          <mx:Script>

          <![CDATA[

           

           

          import

          mx.controls.Alert;

           

           

          private function displayCoords():void

          {

          mx.controls.Alert.show(

           

          "x: " + dg.x + " y: "

          + dg.y);

          }

          ]]>

           

           

          </mx:Script>

           

           

          <mx:DataGrid id="dg" width="500" height="300" x="20" y="15"

          />

           

           

          <mx:Button x="20" y="350" label="Display Coordinates" click="displayCoords()"

          />

          1 person found this helpful
          • 2. Re: Retrieving top-left corner coordinates of a row in datagrid
            Madhav Subedi Level 4

            well, if you want to know the location of ROW  not the DATAGRID, you need to do some tricky calculations.

             

            following is a psuedo code from my view:

             

            1. make the fixed row height for datagrid - variableRowHeight="false"; it is default.

             

            2. calculate two constants: HEADER_HEIGHT and ROW_HEIGHT

             

            3. when selected a row, find its position in the datagrid:

                 position = dataprovider.getItemIndex(datagrid.selectedItem);

             

            4. now calculate the y offset:

                 row_y = datagrid.y + HEADER_HEIGHT + ROW_HEIGHT * (position);

                 row_x = datagrid.x;

             

            Hope it works.

            1 person found this helpful