【问题标题】:Scrollbars in dropdownlist inside DataGrid itemEditor not workingDataGrid itemEditor内下拉列表中的滚动条不起作用
【发布时间】:2010-08-17 20:02:55
【问题描述】:

我的 DataGrid 的 itemEditor 中有一个 DropDownList。 DropDownList 中有足够的项目来证明滚动条的合理性。您可以看到滚动条,并且鼠标滚轮工作正常。如果您将鼠标移到滚动条上,它们会很好地改变外观(鼠标悬停工作)。如果单击它们,DropDownList 会关闭,就像您单击数据网格中的其他位置一样。

Adobe Forums 上有评论描述了同样的问题,但是比较老了,还没有回答。

我一直在尝试自定义皮肤,希望找到一种方法来捕获鼠标事件,但没有成功。

FWIW,这是 Flex4,作为 AIR 应用程序。

Scratch.mxml(主要代码)

    <?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx"
        creationComplete="windowedapplication1_creationCompleteHandler(event)">
 <fx:Script>
  <![CDATA[
   import mx.collections.ArrayCollection;
   import mx.events.FlexEvent;
   [Bindable] public var dataList:ArrayCollection = new ArrayCollection();

   protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
   {
    var o:Object = new Object();
    
    o.theChoice = "abc";
    o.choices = new ArrayCollection();
    o.choices.addItem("abc");
    o.choices.addItem("def");
    o.choices.addItem("ghi");
    o.choices.addItem("jkl");
    o.choices.addItem("mno");
    o.choices.addItem("pqr");
    o.choices.addItem("stu");
    o.choices.addItem("vwx");
    o.choices.addItem("yz ");
    dataList.addItem(o);
   }
   protected function col2Label(item:Object, column:DataGridColumn):String {
    return item.theChoice;
   }
   // If you use the labelFunction, then you must specify a sortCompareFunction
   private function sortCol2(obj1:Object, obj2:Object):int
   {
    var d1:String = obj1.col2 as String;
    var d2:String = obj2.col2 as String;
    if(d1 < d2) {
     return -1;
    } else if(d1 == d2) {
     return 0;
    }
    return 1;
   }

  ]]>
 </fx:Script>
 <fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
 </fx:Declarations>
 <mx:DataGrid id="glGrid" top="10" left="10" right="10" bottom="10"
     dataProvider="{dataList}" editable="true" >
  
  <mx:columns>
   <mx:DataGridColumn id="col2" 
          headerText="Column 2"  
          itemEditor="Renderers.ddlRenderer" 
          labelFunction="col2Label" 
          dataField="col2"
          sortCompareFunction="sortCol2"/>
  </mx:columns>  
 </mx:DataGrid>
</s:WindowedApplication>

ddlRenderer.mxml:

    <?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">
 <fx:Script>
  <![CDATA[
   import mx.collections.ArrayList;
   
   import spark.events.IndexChangeEvent;
   
   [Bindable] private var myChoices : ArrayList = new ArrayList();
   
   override public function set data(value:Object):void
   {
    if (value != null) {
     super.data = value;
     if (ddl && myChoices) {
      myChoices.removeAll();
      var theChoice:String = value.theChoice;
      
      myChoices.addAll(value.choices);
      
      var lineChoice : String;
      for (var i:int = 0; i < myChoices.length; i++) {
       lineChoice = myChoices.getItemAt(i) as String;
       if (lineChoice == theChoice) {
        ddl.selectedItem = lineChoice;
        break;
       }
      }
     }
    }
   }
   
  ]]>
 </fx:Script>
 
 <s:DropDownList id="ddl" 
     width="100%" 
     dataProvider="{myChoices}"/>
</s:MXDataGridItemRenderer>

要查看问题,运行代码,点击“abc”触发itemRenderer,点击DropDownList查看选项,然后尝试点击滚动条。

我被这个难住了,非常感谢一些帮助。

谢谢

【问题讨论】:

  • +1 用于提供可运行的代码。

标签: apache-flex drop-down-menu mouse flex4 scrollbar


【解决方案1】:

我将此作为错误(SDK-27783、Flex SDK、Spark:DropDownList)发布到 Adob​​e,今天刚刚关闭。 Alex Harui 有一个很好的解决方法:

解决方法是按如下方式更改渲染器:

<s:DropDownList id="ddl" 
 width="100%" 
 dataProvider="{myChoices}" open="ddl.skin['dropDown'].owner = this"/>

我对此进行了测试,它解决了我的问题。希望这对其他人也有帮助。

【讨论】:

  • 感谢您发布此问题,我已经为这个问题苦苦挣扎了几天,终于找到了这个解决方案!
  • +1... 虽然这并不完美。一旦 itemEditor 启动,我无法移动到其他 itemEditor,直到我单击网格并返回它。
【解决方案2】:

我不确定您是否应该捕获鼠标事件。可以调试框架类:DropDownController.as,在systemManager_mouseDownHandler函数和processFocusOut函数开始处下断点。点击下拉列表的滚动条可以看到systemManager_mouseDownHandler函数没有调用closeDropDown,closeDropDown是由processFocusOut调用的。

现在在您的应用程序顶部添加一个 DropDownList 对象:

<s:DropDownList id="ddltop"
                    top="10"
                    left="10"
                    width="100%"
                    dataProvider="{dataList.getItemAt(0).choices}"
                    />
<mx:DataGrid id="glGrid" top="50" left="10" right="10" bottom="10"

...

并使用相同的断点再次调试。现在调用 closeDropDown 的是 systemManager_mouseDownHandler 函数。

也许是关闭下拉列表的原因。

【讨论】:

    猜你喜欢
    • 2017-05-27
    • 2023-03-11
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    • 1970-01-01
    • 2019-09-01
    • 1970-01-01
    相关资源
    最近更新 更多