【问题标题】:Get or Set Cell Values in a Datagrid progmatically以编程方式获取或设置 Datagrid 中的单元格值
【发布时间】:2011-04-22 19:39:44
【问题描述】:

在使用预填充数据网格的 Flex 4 中,我如何以编程方式获取或设置特定值,即我不会使用 selectedItems 等。

例如,如何引用第 4 行第 6 列中的单元格的值。

请提前感谢您的帮助。

克雷格

【问题讨论】:

    标签: apache-flex actionscript-3 datagrid flex4


    【解决方案1】:

    将 DataGrid 的 dataProvider 转换为 ListCollectionView 并使用其 getItemAt 方法。

    ListCollectionView(dataGrid.dataProvider).getItemAt(requiredRow).appropriateProperty = newValue;
    

    更新:如果列名是动态的,您可以使用以下方式获取它:

    var data_field:String = dgViewPreview.columns[6].dataField; //for 6th column
    ListCollectionView(dataGrid.dataProvider).getItemAt(requiredRow)[data_field] = newValue;
    

    【讨论】:

    • 首先非常感谢您抽出宝贵的时间来回答:好的,我得到了行,我如何得到特定的列
    • 我在一行中有 30 个值我真的只想更新一个特定的项目。
    • 这种情况是当用户在我的数据网格中编辑一个项目时,我需要更新数据网格中的一系列其他值,这些值又会运行网格的某些其他值的总数。
    • 这项工作是否可行:ListCollectionView(dataGrid.dataProvider).getItemAt(requiredColumn,requiredRow).appropriateProperty = newValue;什么是单元格值的适当属性。除了 selectedItem 之外,我找不到任何关于使用单元格的体面文档。哪个不适用于我尝试做的任何事情?
    • @Craig 这取决于您在该特定列中显示的值 - 这就是我使用术语 appropriateProperty 的原因 - 所需 DataGridColumn 的 dataField 是什么?
    【解决方案2】:

    有两种访问方式,基于Grid column DataField Mapping to object property 或 LabelFunction set to grid column

    我在这里粘贴了带有示例的场景 http://pastebin.com/iwrnHD1c

    【讨论】:

      猜你喜欢
      • 2011-02-02
      • 2011-10-12
      • 2010-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-09
      相关资源
      最近更新 更多