1 Reply Latest reply on Feb 3, 2011 4:00 PM by kevinklin

    Populating a Forum froma  data grid in Flex

    Adrien. Level 1

      I have a forum that I would like to pouplate to be able to edit the information in Flex (flash builder four). So how would I click on a row of data (from a datagrid) and have it populate the forum?

        • 1. Re: Populating a Forum froma  data grid in Flex
          kevinklin Adobe Employee

          Hi,

           

          Do you mean a Form? Try listening for the "gridClick" event on the DataGrid and looking at the "item" property of the event. This event dispatches when the user clicks on the DataGrid and item will be the data object from the row that the user clicks on. I've written up a simple example below:

           

          <?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">
              
              <s:layout>
                  <s:VerticalLayout gap="10" paddingTop="10" paddingRight="10" />
              </s:layout>
              
              <fx:Script>
                  <![CDATA[
                      import spark.events.GridEvent;
                      
                      protected function dataGrid_gridClickHandler(event:GridEvent):void
                      {
                          var item:Object = event.item;
                          
                          if (item)
                          {
                              keyTI.text = item.key;
                              nameTI.text = item.name;
                          }
                      }
                  ]]>
              </fx:Script>
              
              <s:DataGrid id="dataGrid" gridClick="dataGrid_gridClickHandler(event)">
                  <s:ArrayCollection>
                      <fx:Object key="1000" name="Abrasive" />
                      <fx:Object key="1001" name="Brush"/>
                      <fx:Object key="1002" name="Clamp"/>
                      <fx:Object key="1003" name="Drill"/>
                      <fx:Object key="1004" name="Epoxy"/>
                      <fx:Object key="1005" name="File" />
                      <fx:Object key="1006" name="Gouge"/>
                      <fx:Object key="1007" name="Hook"/>
                      <fx:Object key="1008" name="Ink" />
                      <fx:Object key="1009" name="Jack" />             
                  </s:ArrayCollection>
              </s:DataGrid>
             
              <s:Form>
                  <s:FormItem label="key">
                      <s:TextInput id="keyTI" />
                  </s:FormItem>
                  <s:FormItem label="name">
                      <s:TextInput id="nameTI" />
                  </s:FormItem>
              </s:Form>
              
          </s:Application>
          
          

           

          Of course, you'll have to write some code so that the you can edit the data and save it from the Form. Hope this helps.

           

          -Kevin