0

实际上我需要使用复选框编码选择数据网格中的行。然后,如果我选择一行,那一行只会打印。如果我没有选择行,请打印所有行。请帮助代码。

                    <mx:DataGrid id="dg" dataProvider="{dp}" allowMultipleSelection="true" selectable="true" height="100%" width="100%" >
                        <mx:columns>

                                <mx:DataGridColumn headerText="Select" dataField="Select" textAlign="center">
                                    <mx:itemRenderer>
                                        <fx:Component id="chkGrid">
                                            <mx:CheckBox click="data.Select=!data.Select" selected="{data.Select}"/>
                                        </fx:Component>
                                    </mx:itemRenderer>
                                </mx:DataGridColumn>

                            <mx:DataGridColumn headerText="Name" dataField="Nname"/>
                            <mx:DataGridColumn headerText="Metal Weight" dataField="metalwgt"/>
                            <mx:DataGridColumn headerText="Diamond Weight" dataField="diamondwgt"/>
                            <mx:DataGridColumn headerText="Metal Carat" dataField="carat"/>
                            <mx:DataGridColumn headerText="Price" dataField="price"/>
                            <mx:DataGridColumn headerText="ImagePath" dataField="imagePathTxt" visible="false"/>
                        </mx:columns>
                    </mx:DataGrid>

                </s:VGroup>
            </s:BorderContainer>

        </s:VGroup>
    </s:HGroup>
</s:BorderContainer>

4

1 回答 1

0

假设print_clickHandler是打印按钮的点击处理程序..那么这就是代码将如何获取那些选定的行..

protected function print_clickHandler():void
{
    var PrintCollection:ArrayCollection = new ArrayCollection;
    // The below code will get you the selected rows..
    for each(var item:Object in dp)
    {
        if(item.hasOwnProperty("Select") && item.Select)
          PrintCollection.addItem(item);
    }

    // PrintCollection is the selected rows collection which you need to print
    // or the below code will also get you the selected rows.. Either of it will work       
    dp.filterFunction = function(item:Object):Boolean
    {
        return (item.hasOwnProperty("Select") && item.Select);
    }
    dp.refresh();

    // dp is the selected rows collection which you need to print
}
于 2013-01-18T06:38:10.823 回答