3 Replies Latest reply on May 10, 2011 10:20 PM by snkd

    how to get that record when i use keyboard up and down key in datagrid?

    flex4 Level 2

      Hi All,

       

            I have a datagrid where I am displaying some records.. there is default property when I click on datagrid we can get the information about that selected record.. it is fine.. If I am using my keyboard up and down arrow keys I want to get that perticular highlighted record from the datagrid. when I use up and arrokeys to rolling rows up and down ...  I want get that record information .. Please help me on this..

       

      Thanks

      Ram

        • 1. Re: how to get that record when i use keyboard up and down key in datagrid?
          snkd Level 1

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

           

          <!--

           

          Project:      

           

          File:        sample.mxml   

           

          Date:        May 9, 2011   

           

          Author:        Sanka Senavirathna-Administrator

           

          -->

           

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"


                         xmlns:s="library://ns.adobe.com/flex/spark"
                         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
             
              <!--View Tier-->
             
             
             
             
              <!--Controller-->
              <fx:Declarations>
                  <!--Validators-->
                 
                  <!--Formatters here-->
                 
                  <!--valueObjects/domains here-->
                 
              </fx:Declarations>
             
             
              <!--Model:Bussiness Logic Here/ActionScript Here-->
              <fx:Script>
                  <![CDATA[
                      import mx.collections.ArrayCollection;
                      import mx.controls.Alert;
                     

           

                      [Bindable]
                      public var inventory:ArrayCollection = new ArrayCollection([
                          {des:"Insurance",isSelected:false},
                          {des:"License",isSelected:false},
                          {des:"Spare Wheel",isSelected:false},
                          {des:"Spare Wheel",isSelected:false},
                          {des:"Spare Jack",isSelected:false},
                          {des:"Spare Jack Handle",isSelected:false},
                          {des:"Spare Wheelbraise",isSelected:false},
                          {des:"Air Con",isSelected:false},
                          {des:"CD Player",isSelected:false},
                          {des:"Cassette",isSelected:false},
                          {des:"Radio",isSelected:false},
                          {des:"Meters",isSelected:false},
                          {des:"Fan Belt",isSelected:false},
                          {des:"Fuses",isSelected:false},
                          {des:"Wrench",isSelected:false},
                          {des:"Screw Driver",isSelected:false},
                          {des:"Seat Covers",isSelected:false},
                          {des:"Carpets",isSelected:false}
                      ]);
                     

           

           

           

                      protected function datagrid1_keyUpHandler(event:KeyboardEvent):void
                      {
                          Alert.show("index :"+event.target.selectedIndex+"\n"+"Description :"+event.target.selectedItem.des);
                      }

           

                  ]]>
              </fx:Script>
              <mx:DataGrid dataProvider="{inventory}" x="317" y="153"
                           keyUp="datagrid1_keyUpHandler(event)">
                  <mx:columns>
                      <mx:DataGridColumn headerText="description" dataField="des"/>
                      <mx:DataGridColumn headerText="selected" dataField="isSelected"/>
                  </mx:columns>
              </mx:DataGrid>
             
          </s:Application>
          • 2. Re: how to get that record when i use keyboard up and down key in datagrid?
            flex4 Level 2

            Hi snkd,

             

                     As I know this ..  but it works for every key in the key board it calls when i click any key in the keyboard.. I dont want it .. But it should work only for keyboard up key and keyboadrd down key

            ..

            • 3. Re: how to get that record when i use keyboard up and down key in datagrid?
              snkd Level 1

              you can write a if condition to check key code.

               

              //I dont know keycode is 38 or something

              if(event.keyCode.toString()=='38' || event.keyCode==Keyboard.UP)

              {

              //your business logic

              //launchSearchGrid();

              }

               

              Try this

                          protected function datagrid1_keyUpHandler(event:KeyboardEvent):void
                          {

              if(event.keyCode==Keyboard.DOWN || event.keyCode==Keyboard.UP)

              {


                              Alert.show("index :"+event.target.selectedIndex+"\n"+"Description :"+event.target.selectedItem.des);

              }

               

              }