3

在 mx:datagrid 上,我使用自定义 itemrenderer 和 itemeditor。当单元格处于编辑模式时,Itemeditor 分隔符在 itemeditor 内可见。

所以它并不漂亮,而且很难阅读你写的东西。

在 itemEditor 上,我尝试使用 contentBackgroundColor 并覆盖 updateDisplayList

请参阅下面的 itemEditor 的所有代码

    <?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                          xmlns:s="library://ns.adobe.com/flex/spark" 
                          xmlns:mx="library://ns.adobe.com/flex/mx" 
                          focusEnabled="true"

                          creationComplete="mxdatagriditemrenderer1_creationCompleteHandler(event)"
                          focusIn="mxdatagriditemrenderer1_focusInHandler(event)">

    <fx:Script>
        <![CDATA[
            import fr.util.UtilString;

            import mx.controls.DataGrid;
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.controls.listClasses.BaseListData;
            import mx.core.FlexGlobals;
            import mx.core.UITextField;
            import mx.events.FlexEvent;
            public var htmlModif:String;
            public var beginIndex:int;
            public var endIndex:int;

            protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
            {
                graphics.beginFill(0xFFFFFF); // white
                graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
                graphics.endFill();

                super.updateDisplayList(unscaledWidth, unscaledHeight);
            }

            override public function validateProperties():void
            {
                super.validateProperties();
                if (listData)
                {
                    var dg:DataGrid = DataGrid(listData.owner);

                    var column:DataGridColumn = dg.columns[listData.columnIndex];

                    var htmlText:UITextField = lblData.htmlText as UITextField;

                }


            }

            protected function lblData_focusOutHandler(event:FocusEvent):void
            {
                beginIndex = lblData.selectionBeginIndex;
                endIndex= lblData.selectionEndIndex;
            }

            protected function mxdatagriditemrenderer1_focusInHandler(event:FocusEvent):void
            {
                lblData.editable=true;
            }

            protected function mxdatagriditemrenderer1_creationCompleteHandler(event:FlexEvent):void
            {
                //set cursor postion to end
                lblData.selectionBeginIndex=lblData.htmlText.length;
                lblData.selectionEndIndex=lblData.htmlText.length+1;
                lblData.addEventListener(MouseEvent.CLICK,copyGloss_focusInHandler);

                lblData.setFocus();             
            }

            // ajout de terme venant du gloassaire
            protected function copyGloss_focusInHandler(event:Event):void
            {
                if(FlexGlobals.topLevelApplication.copyFromGloss){
                    if(Clipboard.generalClipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)){ 


                        var textCpb:String = Clipboard.generalClipboard.getData(ClipboardFormats.TEXT_FORMAT) as String; 


                        var ind:int = new UtilString().calculateHtmlPosition(lblData.htmlText, lblData.selectionBeginIndex);
                        lblData.htmlText = lblData.htmlText.substring(0, ind) + textCpb + " "+lblData.htmlText.substring(ind, lblData.htmlText.length);     
                    }
                    htmlModif=lblData.htmlText;                    
                    Clipboard.generalClipboard.clear(); 
                    FlexGlobals.topLevelApplication.copyFromGloss=false;
                }
            }


        ]]>
    </fx:Script>

    <mx:TextArea id="lblData" top="0" left="0" right="0" bottom="0" 
                 htmlText="{dataGridListData.label}" 
                 wordWrap="true"
                 editable="true"
                 contentBackgroundColor="0xFFFFFF"
                 horizontalScrollPolicy="off"
                 creationComplete="htmlModif=lblData.htmlText"
                 change="htmlModif=lblData.htmlText"
                 focusOut="lblData_focusOutHandler(event)"/>
</s:MXDataGridItemRenderer>

数据网格构建

<mx:DataGrid id="dgSuiviClini"
verticalGridLines="true"
horizontalGridLines="true"
horizontalScrollPolicy="on"
variableRowHeight="true"
dataProvider="{DP_LISTEREDVCLI}"
editable="true"
focusEnabled="true"
dropEnabled="true"
itemEditBegin="dgSuiviClini_itemEditBeginHandler(event)"
itemEditEnd="getCellInfo(event);"
itemFocusOut="getCellInfo(event)"
 width="100%" height="100%"
rowHeight="20">
<mx:columns>

<mx:DataGridColumn dataField="scRub2" headerText="{sNomCol2}" editable="true" 
width="{iNomCol2}"
id="dgc1" wordWrap="true" visible ="{bcol2Visible}"
itemRenderer="fr.ui.itemRenderer.MultilineHTMLRenderer"
itemEditor="fr.ui.itemRenderer.irCliHtmlEditor"
editorDataField="htmlModif"
editorUsesEnterKey="true" />
 </mx:columns>
</mx:DataGrid>

但在这些情况下,结果是这样的: 在此处输入图像描述

如果你能帮助我,我很高兴。

谢谢

4

0 回答 0