3 Replies Latest reply on Jan 14, 2008 9:16 AM by peterent

    creating item renderers

    vij010 Level 1
      Hi,

      I have this MXML code here:

      [code start]
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" width="445" height="247">
      <mx:Script>
      <![CDATA[
      import mx.events.DataGridEvent;
      import mx.events.DataGridEventReason;
      import mx.controls.Alert;

      public function openforedit(Event:DataGridEvent):void
      {
      if(Event.dataField=="active"){

      }
      }
      ]]>
      </mx:Script>
      <mx:XMLList id="myxmldata">
      <employee>
      <name>Christina Coenraets</name>
      <phone>555-219-2270</phone>
      <email>ccoenraets@fictitious.com</email>
      <active>true</active>
      </employee>
      <employee>
      <name>John Coe</name>
      <phone>3433-353-646-465</phone>
      <email>rer@ffe.com</email>
      <active>true</active>
      </employee>
      <employee>
      <name>Fana Coh</name>
      <phone>5535-7575-2424</phone>
      <email>f4fefe@fictitious.com</email>
      <active>true</active>
      </employee>
      <employee>
      <name>Gig Cog</name>
      <phone>32234-42424-64646</phone>
      <email>gig@gt.com</email>
      <active>true</active>
      </employee>
      </mx:XMLList>
      <mx:Panel x="10" y="10" width="425" height="217" layout="absolute">
      <mx:DataGrid x="10" y="10" dataProvider="{myxmldata}" id="mydg" itemEditBeginning="openforedit(event);" editable="true">
      <mx:columns>
      <mx:DataGridColumn headerText="Name" dataField="name"/>
      <mx:DataGridColumn headerText="Phone" dataField="phone"/>
      <mx:DataGridColumn headerText="Email" dataField="email"/>
      <mx:DataGridColumn headerText="Active" dataField="active"
      rendererIsEditor="true" itemEditor="component/mycombo"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:Panel>
      [code end]

      And, I have my simple component here , I doubt if this is the correct way....:

      [code start]
      <?xml version="1.0" encoding="utf-8"?>
      <!-- itemRenderers\dataGrid\component\mycombo.mxml -->
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">
      <mx:List>
      <mx:String>True</mx:String>
      <mx:String>False</mx:String>
      <mx:String>Not Required</mx:String>
      </mx:List>
      </mx:Canvas>

      [code end]

      I have an error at the itemEditor line, the error is " cannot parse value of type mx.core.IFactory from text 'component/mycombo'."


      What is the problem ?...How to solve....all I want is to have a list component as my editor, so that I can choose from True,False, Not Required.

        • 1. Re: creating item renderers
          peterent Level 2
          I think the problem may be your nomenclature: component/mycombo. You want to use package.class, so component.mycombo - in other words, periods and not slashes.

          --peter
          • 2. Re: creating item renderers
            vij010 Level 1
            Hi,

            Is this the correct way to create a component ?

            <?xml version="1.0" encoding="utf-8"?>
            <!-- itemRenderers\dataGrid\component\mycombo.mxml -->
            <mx:List height="76">
            <mx:String>True</mx:String>
            <mx:String>False</mx:String>
            <mx:String>Not Required</mx:String>
            </mx:List>

            When I do this, in the OutLine View, I get an Error for the Root Tag. I have only copied this from the help file. Why does this come ?. I just have a datagrid, that has 4 columns, when the user clicks on the last column titled "Status", I want the list to popup and show some values. In the help i have seen examples for other controls but not the list.

            The list is what I have shown here, but I am unable to make it an editor.
            • 3. Re: creating item renderers
              peterent Level 2
              I didn't read your original post too thoroughly I guess. What you have written for an itemRenderer is not correct. The root tag of any MXML file has to include the namespace so the compiler knows where to find the definition. In your original message you have:
              <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">

              which is fine (you won't need the width and height for an item renderer as as the control will size it to fill the cell).

              If you want a pop-up, you can use a ComboBox:
              <mx:ComboBox>
              <mx:dataProvider>
              <mx:Object label="True" value="true" />
              <mx:Object label="False" value="false" />
              </mx:dataProvider>
              </mx:ComboBox>
              </mx:Canvas>

              If you want a popup list for a person to select a choice, then you are making an itemEditor, not a renderer. So the DataGridColumn tag should read:

              <mx:DataGridColumn itemEditor="yourpackage.yourcomponent" editorDataField="value" ... />

              This is where it gets tricky. See the editorDataField? Your itemEditor must have a property called "value" (or whatever you want) which the DataGrid can call upon to retrieve the new value. So you have to modify your itemEditor code once more:
              <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">
              <mx:Boolean id="value" />
              <mx:ComboBox change="value=event.target.selectedItem.value">
              <mx:dataProvider>
              <mx:Object label="True" value="true" />
              <mx:Object label="False" value="false" />
              </mx:dataProvider>
              </mx:ComboBox>
              </mx:Canvas>

              When the ComboBox is changed by the user, its change event is triggered. This causes the ActionScript code in the change event handler to run. In this case, it copies the selected.value to the value property of the itemEditor.

              This should do what you are looking for.