1 Reply Latest reply on Sep 20, 2007 5:49 PM by ntsiii

    DataGrid with Combobox issue

    Pavan Neeli
      Hi,
      I am new to Flex, and while implementing one of our projects, I am facing one issue.
      I have designed a datagrid with 3 columns which will get data from the data provider, and one column for combobox as below

      <mx:DataGrid id="myDataGrid" dataProvider="{gridData}" x="26" y="59" width="752" height="268" fontSize="11" alternatingItemColors="[#ffffff, #e7e7e4]">
      <mx:columns>
      <mx:DataGridColumn headerText="EID" dataField="EID"/>
      <mx:DataGridColumn headerText="Name" dataField="EMPLOYEENAME"/>
      <mx:DataGridColumn headerText="Current Area" dataField="AREA" />
      <mx:DataGridColumn id="nArea" headerText="New Area" >
      <mx:itemRenderer>
      <mx:Component>
      <mx:ComboBox dataProvider="{outerDocument.nAreas}"
      change="{outerDocument.onChangeCombo(this.selectedLabel,outerDocument.myDataGrid.selected Index)}">
      </mx:ComboBox>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      </mx:columns>
      </mx:DataGrid>

      So, when I get 4 records from the'gridData', 3 combobox will also come in the 'New Area' column.
      User has the option of updating area bu selecting one of the options in the Combobox, and click in 'Save' button.

      The problem is that, when there are more records, datagrid get scrollbar to scrollbar.
      If I select an option for the first record, and scrolldown to last records, and do any selection for the last record's comboboxes, then the first record's combox selection is also changing.
      I am not understanding the problem, It may be due to the event handling i don't know.
      Can anyone give any suggession on this to resolve.


      Thanks in advance.

      Rgds
      Pavan


        • 1. Re: DataGrid with Combobox issue
          ntsiii Level 3
          The problem you are seeing is because item renderers are "recycled". Only the visible renderers, plus a few for buffering. are actually instantiated. When you scroll, each visible renderer is re-drawn with the values from the new item "underneath" it.

          The solution is to have the itemRenderer update the dataProvider item when the user changes a value, and have the renderer's components state set by values in the dataProvider item.

          This is a bit complicated with the Combo box, because yo will need to progrmatically set the selectedIndex of the combobox within the renderer. While possible, it will be difficult to do this in an in-line renderer, I advise creating a component.

          Google this , there are many examples of itemRenderers available.

          Tracy