我有两个数据网格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中的编辑值?任何人都可以有解决方案?
我修改了TextInputRenderer.as中的set数据方法以显示编辑后的文本。 – Eswaran 2011-03-28 09:33:52
@Eswaran这是否解决了您的问题?或者帮助解决你的问题? – JeffryHouser 2011-03-28 11:47:07
它解决了这个问题。 – Eswaran 2011-03-28 11:51:56