2

除非我在这里遗漏了一些明显的东西,否则无法禁用 DataGrid 中的一行或多行。我希望 DataGrid 或 List 组件上有 disabledRows 或 disabledRowIndidices 属性,但这似乎不存在。

我找到了一个“rendererArray”属性,其范围为 mx_internal,包含数据网格中所有单元格的所有 itemrenderer。所以我可以检查渲染器中数据的类型和值,并启用或禁用同一行的所有单元格,但这感觉太像黑客了。

有什么建议么?

编辑:我意识到禁用一行可能意味着不同的事情。在我的情况下,这意味着即使数据网格的可编辑属性设置为 true,也无法编辑该行。然而,这也可能意味着无法选择一行,但这不是我想要的。

4

4 回答 4

6

为此,您需要该行的一些数据来表示它是不可编辑的。然后当“itemEditBeginning”然后检查数据或行索引以启用/禁用 event.preventDefault 的默认行为...

public function preventEditing(event:DataGridEvent):void
{   
    var status : Boolean = ArrayObjs[rowIndex].isYourCondition;

    if (status == true)
    {
        event.preventDefault();
    }
}

另一种选择是为您的数据单元格制作自定义 ItemRenderer,但不要认为这是您想要的,因为您需要为每个单元格制作它。

于 2009-06-08T02:53:05.057 回答
2

实际上这最好通过“itemEditBeginning”来完成。在这里寻找一个好的教程:链接文本

于 2009-03-10T18:56:39.410 回答
0

Alex Harui 在此处提供了一个很好的示例,源代码http://blogs.adobe.com/aharui/2007/06/disabling_list_selection.html 这是一个有点冗长的解决方案,但涵盖了鼠标和键盘与数据网格的交互。我同意你的看法,令人惊讶的是没有“内置”方法来做到这一点。

于 2009-02-19T06:17:27.550 回答
0

只需为 DataGrid 的“itemEditBegin”设置一个函数,执行如下操作:

protected function validateEdition(event:DataGridEvent):void{
    if([EDITION CRITERA NOT MET]){
          event.preventDefault();
    }
}

<mx:DataGrid id="grid" itemEditBegin="validateEdition(event)" editable="true">
      <mx:columns>
         [[YOUR COLUMN CONFIGURATION]]
      </mx:columns>
</mx:DataGrid> 

event.preventDefault() 将阻止 DataGrid 将 ItemRenderer 切换到 ItemEditor 以便停止不符合条件的行的版本。您的 DataGrid 必须是可编辑的,它才能工作。

这应该可以解决问题。

于 2010-01-13T19:15:42.830 回答