2 Replies Latest reply on Jul 28, 2010 3:37 AM by Sangeeta Kalyani

    grid issue

    bindu84

      i have that code for data grid

       

       

      <?xml version="1.0"?> <!-- dpcontrols/DataGridEvents.mxml --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"> <mx:Script> <![CDATA[ import mx.events.ListEvent; private function itemClickEvent(event:ListEvent):void { clickColumn.text=String(event.columnIndex); clickRow.text=String(event.rowIndex); eventType.text=event.type; } ]]> </mx:Script> <mx:DataGrid id="myGrid" width="350" height="150" itemClick="itemClickEvent(event);"> <mx:ArrayCollection> <mx:Object Artist="Pavement" Price="11.99" Album="Slanted and Enchanted" /> <mx:Object Artist="Pavement" Album="Brighten the Corners" Price="11.99" /> </mx:ArrayCollection> </mx:DataGrid> <mx:Form> <mx:FormItem label="Column Index:"> <mx:Label id="clickColumn"/> </mx:FormItem> <mx:FormItem label="Row Index:"> <mx:Label id="clickRow"/> </mx:FormItem> <mx:FormItem label="Type:"> <mx:Label id="eventType"/> </mx:FormItem> </mx:Form> </mx:Application>

       

       

       

      on itemclick i got the value properly, but by moving keyboard up/down key i m not getting the value,

      Can anyone help which event is requird for that i have focusii/out, but not working

        • 1. Re: grid issue
          BhaskerChari Level 4

          Hi Bindu,

           

          Check the code below:

           

          While you are using the KeyBoard you cannot get the First FormItem value which is ColumnIndex...Since you can get the ColumnIndex for only itemClick event....there is not question of getting the CoulmnIndex for keyboard event...

           

          You can get the rowIndex and the event type.....whereas ColumnIndex is not possible for KeyBoard selection..

           

          You can use either KeyUp event or KeyDown event.....the only difference you get is the event type..

           

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
          <mx:Script>
          <![CDATA[
          import mx.events.ListEvent;
          private function itemClickEvent(event:ListEvent):void
          {
            clickColumn.text=String(event.columnIndex);
            clickRow.text=String(event.rowIndex);
            eventType.text=event.type;
          }
          private function onKeyDown(event:KeyboardEvent):void
          {
            //clickColumn.text=String(event.columnIndex);
            clickRow.text = myGrid.selectedIndex.toString();
            eventType.text = event.type;
          }

           

          ]]>
          </mx:Script>
          <mx:DataGrid id="myGrid" keyDown="onKeyDown(event)" width="350" height="150" itemClick="itemClickEvent(event);">
            <mx:ArrayCollection>
             <mx:Object Artist="Pavement" Price="11.99" Album="Slanted and Enchanted" />
             <mx:Object Artist="Pavement" Album="Brighten the Corners" Price="11.99" />
            </mx:ArrayCollection>
          </mx:DataGrid>
          <mx:Form>
            <mx:FormItem label="Column Index:">
             <mx:Label id="clickColumn" />
            </mx:FormItem>
            <mx:FormItem label="Row Index:">
             <mx:Label id="clickRow" />
            </mx:FormItem>
            <mx:FormItem label="Type:">
             <mx:Label id="eventType"/>
            </mx:FormItem>
          </mx:Form>
          </mx:Application>

           

           

          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari

          • 2. Re: grid issue
            Sangeeta Kalyani

            Hi Bindu,

             

            Try this.

             

            <?xml version="1.0"?>

            <!-- dpcontrols/DataGridEvents.mxml -->

             

             

            <mx:Application

             

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

            <mx:Script>

             

            <![CDATA[

             

            import mx.events.DataGridEvent;

             

            import mx.events.ItemClickEvent;

             

            import mx.events.ListEvent;

             

             

            private var selectedColumn:int = 0;

             

             

            private function itemClickEvent(event:ListEvent):void {

            clickColumn.text=String(event.columnIndex);

            selectedColumn = event.columnIndex;

            clickRow.text=String(event.rowIndex);

            eventType.text=event.type;

            }

             

             

            private function changeEvent(event:ListEvent):void {

            clickColumn.text=selectedColumn.toString();

            clickRow.text=String(event.rowIndex);

            eventType.text=event.type;

            }

            ]]>

             

             

             

            </mx:Script>

             

             

            <mx:DataGrid id="myGrid" width="350" height="150" itemClick="itemClickEvent(event);" change="changeEvent(event);">

             

             

             

            <mx:ArrayCollection>

             

            <mx:Object Artist="Pavement" Price="11.99" Album="Slanted and Enchanted" />

             

            <mx:Object Artist="Pavement" Album="Brighten the Corners" Price="11.99" />

             

            </mx:ArrayCollection>

             

             

            </mx:DataGrid>

             

            <mx:Form>

             

            <mx:FormItem label="Column Index:">

             

            <mx:Label id="clickColumn"/>

             

            </mx:FormItem>

             

            <mx:FormItem label="Row Index:">

             

            <mx:Label id="clickRow"/>

             

            </mx:FormItem>

             

            <mx:FormItem label="Type:">

             

            <mx:Label id="eventType"/>

             

            </mx:FormItem>

             

            </mx:Form>

             

            </mx:Application>

             

             

            Regards,

            Sangeeta Kalyani