2011-03-25 109 views
0

我有两个数据网格1. OPTION GRID和2. ELECTION GRID。我在使用描述列中的TextInput组成的ELECTION GRID中使用了VBox容器作为itemRenderer。以下是示例SWF。在TextInput中编辑的值在滚动时折叠,在DataGrid中用作itemRenderer

无论何时在OPTION GRID中选中复选框,我必须在第2个网格(ELECTION GRID)中为所有行添加一个带有描述值的相应文本输入。假设如果选择了两个复选框,我必须在第二个网格中添加两个textinput,等等......这工作正常。但每当我编辑textinput并向上或向下滚动,该值会在行之间折叠或消失。 我怀疑itemRenderer会在滚动时重新用于其他行。如何保留textinput中的编辑值?

以下是代码。

主代码:

<mx:VBox width="100%" height="100%"> 
    <mx:Label text="OPTION GRID :" fontSize="12" fontStyle="normal" fontThickness="15"/>   
    <components:CAEventDetailDataGrid width="100%" height="20%" dataProvider="{optionData}" allowMultipleSelection="true" optionSelected="onOptionSelection(event)">   
     <components:columns> 
      <mx:DataGridColumn dataField="selected" headerText="Select All" itemRenderer="renderer.CheckBoxItemRenderer" width="70" textAlign="center"/> 
      <mx:DataGridColumn dataField="optionId" headerText="Option" textAlign="left"/> 
      <mx:DataGridColumn dataField="option" headerText="Description" textAlign="left"/> 
     </components:columns>  
    </components:CAEventDetailDataGrid> 
    <mx:Label text="ELECTION GRID :" fontSize="12" fontStyle="normal" fontThickness="15"/> 
    <mx:DataGrid id="electionGrid" width="100%" height="30%" dataProvider="{electionSummary}" rowCount="3" verticalScrollPolicy="on" variableRowHeight="true">      
     <mx:columns> 
      <mx:DataGridColumn dataField="dbProduct" headerText="DB Product"/> 
      <mx:DataGridColumn dataField="entitledQty" headerText="Entitled Quantity"/> 
      <mx:DataGridColumn dataField="entityId" headerText="Entity Id"/> 
      <mx:DataGridColumn dataField="entityName" headerText="Entity Name"/> 
      <mx:DataGridColumn dataField="eventStatus" headerText="Event Status"/>    
      <mx:DataGridColumn dataField="option" headerText="Description" itemRenderer="renderer.TextInputRenderer"/>    
     </mx:columns>     
    </mx:DataGrid> 
</mx:VBox> 

<mx:Script> 
    <![CDATA[ 
     import event.ElectionEvent; 


     private function onOptionSelection(electionEvent : ElectionEvent) : void 
     {  
      electionGrid.dispatchEvent(new ElectionEvent(ElectionEvent.OPTION_SELECTED,electionEvent.item)); 
     } 

    ]]> 
</mx:Script> 

TextInputRenderer:

public class TextInputRenderer extends VBox 

override public function set data(value:Object):void 
    { 
     _data = value;   
     _dataGrid = owner as DataGrid; 
     if(_dataGrid) 
      _dataGrid.addEventListener(ElectionEvent.OPTION_SELECTED,addTextInput); 
    } 

    private function addTextInput(electionEvent : ElectionEvent) : void 
    { 
     var option : CAEventOption = electionEvent.item as CAEventOption; 

     if(option != null) 
     { 
      var textInput : TextInput = getChildByName(option.option) as TextInput; 

      if(textInput == null) 
      { 
       textInput = new TextInput; 
       textInput.name = option.option;     
       textInput.text = option.option;     
       textInput.percentWidth = 100; 
       textInput.percentHeight = 100; 
       textInput.visible = textInput.includeInLayout = option.selected; 
       addChild(textInput); 
      } 
      else 
      { 
       textInput.visible = textInput.includeInLayout = option.selected; 
      } 
     } 
    } 

选举事件是每当选择的复选框将被触发并调用监听功能addTextInput定制事件/在去选择的选项网格。

private function addTextInput(electionEvent : ElectionEvent) : void 

是他们的方式来保留TextInput中的编辑值?任何人都可以有解决方案?

回答

1

我怀疑的itemRenderer将 被重新使用,而 滚动其他行。如何保留的TextInput

正确确定itemRenderer的整个目的的编辑 值是为你要跟通过列表基于类的滚动它被重用。它不会渲染你的类中的所有项目,它只会呈现你正在显示的4-10(或其他)。并在您滚动时重新使用这些DisplayObject。

您的代码看起来像是将一个新的TextInput添加到单个itemRenderer中,但很难分辨。您忘记了包含指向您应用的链接。

如何保留编辑值 textinput?

通常您将值存储在对象的dataProvider中;不要根据某些外部事件来改变它。所以,当你在“onItemSelect”方法中,你会添加一个项目到第二个DataGrid的数据,这反过来会创建一个newRenderer,它应该能够通过该渲染器的data属性“创建自己”。

+0

我修改了TextInputRenderer.as中的set数据方法以显示编辑后的文本。 – Eswaran 2011-03-28 09:33:52

+0

@Eswaran这是否解决了您的问题?或者帮助解决你的问题? – JeffryHouser 2011-03-28 11:47:07

+0

它解决了这个问题。 – Eswaran 2011-03-28 11:51:56

相关问题