2 Replies Latest reply on Feb 8, 2011 7:11 AM by z.cristiano

    Datagrid selectItem

    z.cristiano

      Hello...

      I have insert a datagrid this file list.mxml

       

      <mx:Script>

       

      private function modifica_gm():void

      {

      var win:gestione_menu_m = PopUpManager.createPopUp(this, gestione_menu_m, true) as gestione_menu_m;

      PopUpManager.centerPopUp(win);

      }

       

      </mx:Script>

       

      <mx:DataGrid id="lettura_gm" width="499" height="317" dataProvider="{read_gestione_menu.lastResult.users.user}" doubleClickEnabled="true" doubleClick="modifica_gm()">

      <mx:dataProvider>
               <mx:ArrayCollection>
                  <mx:source>
                     <mx:Object Artist="Pavement" Price="11.99" 
                        Album="Slanted and Enchanted" />
                     <mx:Object Artist="Pavement" 
                        Album="Brighten the Corners" Price="11.99" />
                  </mx:source>
               </mx:ArrayCollection>
            </mx:dataProvider>
            <mx:columns>
               <mx:DataGridColumn dataField="Artist" />
               <mx:DataGridColumn dataField="Album" />
               <mx:DataGridColumn id="price" dataField="Price" visible="false"/>
            </mx:column

      </mx:DataGrid>

       

      This is file chec.mxml

       

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

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

      layout="absolute"

      showCloseButton="true"

      title="Modifica Gestione Menu"

      width="556"

      height="482"

      close="PopUpManager.removePopUp(this);">

       

      <mx:Script source="../src/menu_m.as" />

       

      <mx:Form x="0" y="0" width="536" height="442">

      <mx:FormItem label="Title" fontWeight="bold">

      <mx:TextInput width="440" id="title_check" text="{lettura_gm.selectItem.Album"/>

      </mx:FormItem>

      </mx:Form>

       

      </mx:TitleWindow>

       

      It isn't work!

       

      THis function that is if I doublick example "Album -> Brighten the Corners" appears a PopUpManager, I'm not successful that when i doubleclick "Album -> Brighten the Corners" appear a PopUpManager with a textInput wirte "Brighten the Corners", how it is made?

        • 1. Re: Datagrid selectItem
          oldMster Level 3

          You should use the itemDoubleClick event instead of doubleClick - doubleClick is a generic mouse event that doesn't contain enough information to do what you want.

           

          You need to pass the ListEvent generated by the itemDoubleClick to the function modifica_gm, and use it to determine the item that was double clicked on.  Your code assumes that the currently selected item is the item that was double clicked, which isn't necessarily the case. 

           

          The datagrid event handler would be changed to:

           

          itemDoubleClick="modifica_gm(event);"

           

          and the modifica_gm function definition would change to:

           

          private function modifica_gm(event:DataGridEvent):void {

           

          In the modifica_gm function, the item double click on will be in event.currentTarget.selectedItem.

           

          Below is less functional example that should point you in the correct directions.  Note that I'm using Flash builder 4, so I had to change some of the mx declarations to fx, you may have to change them back.

           

          Mark

           

           

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

          <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"

             >

          <fx:Declarations>

          <!-- Place non-visual elements (e.g., services, value objects) here -->

          </fx:Declarations>

          <fx:Script>

           

          import mx.controls.Alert;

          import mx.events.ListEvent;

           

           

           

          private function modifica_gm(event:ListEvent):void

          {

           

          Alert.show(event.currentTarget.selectedItem.Album);

           

          }

           

           

          </fx:Script>

           

          <mx:DataGrid id="lettura_gm" width="499" height="317"  doubleClickEnabled="true" itemDoubleClick="modifica_gm(event);">

          <mx:dataProvider>

          <mx:ArrayCollection id="myProvider">

          <mx:source>

          <fx:Object Artist="Pavement" Price="11.99"

             Album="Slanted and Enchanted" />

          <fx:Object Artist="Pavement"

             Album="Brighten the Corners" Price="11.99" />

          </mx:source>

          </mx:ArrayCollection>

          </mx:dataProvider>

          <mx:columns>

          <mx:DataGridColumn dataField="Artist" />

          <mx:DataGridColumn dataField="Album" />

          <mx:DataGridColumn id="price" dataField="Price" visible="false"/>

            </mx:columns>

          </mx:DataGrid>

           

          </s:Application>

          • 2. Re: Datagrid selectItem
            z.cristiano Level 1

            I'm not successful!

            HELP ME...

             

            I have insert on INDEX.MXML

             

            <mx:Script>

             

            import mx.events.ListEvent;

             

             

            private function modifica_gm(event:ListEvent):void

            {

            var win:gestione_menu_m = PopUpManager.createPopUp(this, gestione_menu_m, true) as gestione_menu_m;

             

            find.text = event.currentTarget.selectedItem.titolo;

             

            PopUpManager.centerPopUp(win);

            }

             

             

            </mx:Script>

             

             

            <mx:DataGrid id="lettura_gm" width="499" height="317" doubleClickEnabled="true" itemDoubleClick="modifica_gm(event)">

            <mx:columns>

            <mx:DataGridColumn headerText="" dataField="id_gm" itemRenderer="mx.controls.CheckBox" rendererIsEditor="true"/>

            <mx:DataGridColumn headerText="Data" dataField="data"/>

            <mx:DataGridColumn headerText="Titolo" dataField="titolo"/>

            <mx:DataGridColumn headerText="Pos." dataField="posizione"/>

            <mx:DataGridColumn headerText="" dataField="pubblicare"/>

            </mx:columns>

            </mx:DataGrid>

             

            On file GESTIONE_MENU_M.MXML

             

             

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

            layout="absolute"

            showCloseButton="true"

            title="Modifica Gestione Menu"

            width="556"

            height="482"

            close="PopUpManager.removePopUp(this);">

             

             

            <mx:Form x="0" y="0" width="536" height="442">

            <mx:FormItem label="Titolo" fontWeight="bold">

            <mx:TextInput width="440" id="titolo" text="{find.text}"/>

            </mx:FormItem>

            </mx:Form>

             

             

            </mx:TitleWindow>

             

            WHat have I mistaken?