本文介绍了在FLEX中滚动时,datagrid中的CheckBox itemrenderer被选中/未选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个动态创建的数据网格。
对于datagrid中的每个单元,我都有一个复选框作为itemrenderer。
到目前为止,它按预期工作正常。但是,在垂直滚动时,复选框会自动被选中/取消选中。我在水平滚动中也遇到了同样的问题,但是我通过为每列设置 minWidth来解决。

In my application i am having a datagrid which was created dynamically.For each and every cell in datagrid, i am having checkbox as itemrenderer.As of now it is working fine as expected.But while scrolling vertically the checkboxes getting selected/unselected automatically.I got this same problem in "horizontal scrolling" also, but i resolved it by setting "minWidth" for each columns.

我正在这样创建数据网格,

I am creating datagrid like this,

for(i=0;i<recordCount;i++)
            {
                var obj:Object = new Object();
                for(var j:int=0;j<maxPages;j++){

                    {
                        obj["page"+(j+1)]=((xml..item.(pageOrder==(j+1))).length()>i)?(xml..item.(pageOrder==(j+1)))[i].pageTempVerId[0].toString()+" ("+(xml..item.(pageOrder==(j+1)))[i].pageVerUserName[0].toString()+")":"";

                    }

                }
                dp.addItem(obj);
            }

for(i=0;i<maxPages;i++)
            {
                var printPDFItemrenderer:ClassFactory = new ClassFactory(PrintPDFCheckboxComponent)
                printPDFItemrenderer.properties = {onClick: printpdfchkid_clickHandler};
                var grid:DataGridColumn = new DataGridColumn();
                grid.itemRenderer = printPDFItemrenderer;
                grid.headerText = pageName[i];
                grid.width = 150;
                grid.minWidth = 150;
                grid.dataField = "page" + (i+1);
                if(recordCount<(xml..item.(pageOrder==(i+1))).length())
                    recordCount = (xml..item.(pageOrder==(i+1))).length()
                col.push(grid);
            }
            printpdfdg.columns = col;


<mx:DataGrid id="printpdfdg" width="100%" height="380"
                     textAlign="center"  dataProvider="{dp}" sortableColumns="false" horizontalScrollPolicy="off" verticalScrollPolicy="auto" rowHeight="40" horizontalCenter="0" variableRowHeight="false">
        </mx:DataGrid>

在itemrenderer mxml文件中

In the itemrenderer mxml file

<mx:checkBox id="printpdfchkid" label="{data[DataGridListData(listData).dataField]}"
            selected="{data.data[DataGridListData(listData).dataField]}" labelPlacement="right" labelVerticalOffset="0"
            click="onClick(event)" />

所以任何人都可以发现我在做什么错

So anyone can found what i am doing wrong

推荐答案

我也有同样的经历。若要解决此问题,请在对象中添加一个布尔属性,然后尝试在项目渲染器中遵循给定的代码。

i had same experience. to solve this problem add a boolean property in your object and then try to follow given code in your item renderer.

private var _obj:Object;

public function get obj():Object
        {
            return _obj;
        }

        public function set obj(value:Object):void
        {
            _obj = value;
        }
override public function set data(value:Object) : void
        {
            this.itemCheckBox.label = value.Name;
            this.itemCheckBox.selected = value.isSelected;
            obj = value;


        }
//check box change event handler
protected function itemCheckBox_changeHandler(event:Event):void
        {
            obj.isSelected = itemCheckBox.selected;
        }

这篇关于在FLEX中滚动时,datagrid中的CheckBox itemrenderer被选中/未选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:13