3 Replies Latest reply on Jun 30, 2008 8:15 AM by Karl_Sigiscar_1971

    Adding combo box to advanced data grid column

    RBKB
      Hi,

      I need to add a combo box to one of the column in Advanced Data Grid &
      populate it with some data from a data source.

      When an item is selected from the combo box I need to send a HTTP
      request, but using a value in another column of the same advanced data
      grid.

      I have used a itemRenderer and added a hbox & combo box in it. But I
      am not able to read the value of another column. Can somebody help me
      and let me know how would I read the value in another column?

      Thanks in advance.
        • 1. Re: Adding combo box to advanced data grid column
          Karl_Sigiscar_1971 Level 3

          Hi,

          The data property of the item renderer corresponds to the row in your datagrid.

          So, you can very easily access the value of another column by just typing:
          data.propertyName, propertyName being the dataField used in the other column in the datagrid.

          Regards,
          Karl Sigiscar.
          • 2. Re: Adding combo box to advanced data grid column
            RBKB Level 1
            Hi,

            Thanks for your reply. But I could not understand how to use the data property & where to use it?
            Inside the item renderer I have following:

            <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml"
            width="100%"
            dataChange="setSelectedItem(event)"
            creationComplete="loadConfiguration();initComponent();">

            Now inside initComponent() function, if I try to use:

            data.tempId (tempId is the dataField used in AdvancedDataGridColumn), but this gives me "cannot access property of null object reference" error. Can you please guide me more how to use the data property?

            Thanks in advance.
            • 3. Adding combo box to advanced data grid column
              Karl_Sigiscar_1971 Level 3
              The data property of the item renderer corresponds to the item the item renderer renders (a lot of repetitions here... :-).

              But when your application starts, the data property of your item renderer is null. Still, the code is executed. So you get a null pointer exception.

              How to solve this problem ?

              Use databinding within the item renderer in order to detect the data value change from null to an object value:

              <mx:Binding source="{this.data}" destination="onDataChanged" />

              private function set onDataChanged(value:Object):void
              {
              if(value)
              {
              // Do something if value is non-null
              }
              }

              Voila !

              No more errors.

              Since the item has a type in the dataprovider of my datagrids in my projects, I cast the data property to an explicit type before accessing the item properties:

              E.g
              (this.data as Product).ISBN