Flex4中Datagrid垂直滚动使combobox&dropdownlist数据消失(已解决)

时间:2022-01-15 19:22:49

Flex ComboBox in a Datagrid loses values when I scroll horizontally。

使用Flash Builder4+.Net开发,在一个datagrid中使用了自定义的itemrenderer,是一个Dropdownlist,但是滚动datagrid的滚动条,发现ddl中的数据都不见了。

自己研究无果,也是google,找到这篇文章,和我同样的问题:http://*.com/questions/1900591/flex-combobox-in-a-datagrid-loses-values-when-i-scroll-horizontally

据说原因是这个:http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html

简单说就是:adobe的设计小组基于性能和低内存的考虑,设计了recycling机制,只负责“看得见”的控件,对于那些由于滚动而被遮盖的控件,用户需要自己编码在必要的时候更新其value。

~~o(>_<)o ~~

目前还没有找到好的解决方法,期待大大指点╭(╯3╰)╮

Flex4中Datagrid垂直滚动使combobox&dropdownlist数据消失(已解决)

 

================分割线==========================

在乱试一通后找到解决方法:

Datagrid代码:

Flex4中Datagrid垂直滚动使combobox&dropdownlist数据消失(已解决)Flex4中Datagrid垂直滚动使combobox&dropdownlist数据消失(已解决)代码
< mx:DataGrid id = " dgList "  width = " 100% "   height = " 100% "  dataTipFunction = " buildToolTip "   >
                
< mx:columns >                     
                    
< mx:DataGridColumn dataField = " Xbrl "  headerText = " XBRL "  
                                       itemRenderer
= " cons.com.epro.child.myCombox "   />                     
                    
< mx:DataGridColumn headerText = " Column1 "  dataField = " Column1 "  width = " 200 "  showDataTips = " true " />
                    
< mx:DataGridColumn headerText = " NOTE "  dataField = " NOTE "  width = " 50 " />
                    
< mx:DataGridColumn headerText = " Column3 "  dataField = " Column3 "  width = " 120 " />
                    
< mx:DataGridColumn headerText = " Column4 "  dataField = " Column4 "  width = " 120 " />
                
</ mx:columns >
            
</ mx:DataGrid >

自定义扩展控件cons.com.epro.child.myCombox的代码:

Flex4中Datagrid垂直滚动使combobox&dropdownlist数据消失(已解决)Flex4中Datagrid垂直滚动使combobox&dropdownlist数据消失(已解决)代码
< s:DropDownList id = " dXbrl "  labelField = " pdf_item "  dataProvider = " {data.Xbrl as ArrayCollection} "  width = " 100% "                     creationComplete = " dXbrl_creationCompleteHandler(null) "  
                    toolTip
= " {dXbrl.selectedItem.pdf_item} "    />

其中给Dropdownlist赋值的函数为:dXbrl_creationCompleteHandler

关键在datagrid的scroll事件中我们需要调用赋值函数,重新赋值,所以在自动以控件的CreatedCompleted中加入对datagrid的Scroll的监听:

private  function cc(): void {
                
if (owner  is  DataGrid)
                    DataGrid(owner).addEventListener(
" scroll " , dXbrl_creationCompleteHandler);
            }

嗯,大致解决了,O(∩_∩)O~

Flex4中Datagrid垂直滚动使combobox&dropdownlist数据消失(已解决)