我有兩個數據網格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