3 Replies Latest reply on Oct 21, 2007 11:22 PM by KUMBHI

    Combobox in Datagrid with different values

      Hi All,
      I have a datagrid. One of the columns in the datagrid is set to display a combobox as the ItemRenderer. Now, the data for the combobox is different for each row. How do I set up the data provider for the combobox in such a scenario.

      For example : I have a collection of Shirt objects.
      public class Shirt {
      public String id;
      public String type;
      public String[] color; //this is an array

      This should be displayed in the datagrid, with the Color column rendered as a combobox. The colors will be different for each shirt.

        • 1. Re: Combobox in Datagrid with different values
          atta707 Level 2
          How about setting the combo box as itemEditor and overriding it's

          overirde public function set date(value:Object): void

          method and set the reset the data to whatever data you need to set for this row?

          • 2. Re: Combobox in Datagrid with different values
            ntsiii Level 3
            Yes. Some more detail:
            in the function,
            override public function set data(value:Object): void {
            the "value" parameter will contain a refernce to an entire "Shirt" instance.

            So you can assign the comboBox.dataProvider=value.color;

            Now, It is more complicated than this, because you will want the combobox to show the correct value for each row, right?

            For this to happen, you will need a selectedColor property on Shirt. When the user chooses a color, you will need to update this property with the selection.

            Next, your renderer must read the value of selectedColor and set the comboBox.selectedIndex.

            If selectedColor contains the *index* of the color then you have it easy. If it contains the color name itself, then you will have to for-loop over the color array until yom match the selectedColor. then you will have the index and can set selectedIndex.

            ComboBox does not support setting the value directly. It is pretty easy to extend combo to do this. There are several examples out there. I posted a link to one on CFLEX.net

            • 3. Re: Combobox in Datagrid with different values
              KUMBHI Level 1
              Thanks ATTA and Tracy,
              overriding the set data worked.

              Thanks again