Datagrid在特定列as3中选择行(Datagrid selected row at a certain column as3)

编程入门 行业动态 更新时间:2024-10-25 14:23:53
Datagrid在特定列as3中选择行(Datagrid selected row at a certain column as3)

我需要通过AS3获取所选行中特定列的值,我该怎么做?

当我尝试grid.SelectedItem.text时,它保持返回null

谢谢您的帮助! 我需要能够通过名称引用列,在这种情况下是“ID”。

编辑:这是否需要事件或什么? 不应该有内置的方法吗? 你会这样想的...

I need to get the value of a certain column in the selected row via AS3, how can I do this?

It keeps returning null when I try grid.SelectedItem.text...

Thanks for the help! I need to be able to reference the column by name, in this case "ID".

EDIT: Does this require an event or something? Shouldn't there be a method for this built in? You'd think so...

最满意答案

你能更具体一点吗?

您可以使用selectedItem.yourProperty从DataGrid获取所需的所有数据。 你能发布一个可能让事情变得清晰的代码片段吗?

通过名称引用列很容易:

myDataGrid.getColumnAt(myDataGrid.getColumnIndex('ID'))

数据位于DataGrid的dataProvider中,该列出于其他目的。

假设你有一个ID属性添加到DataGrid中:

var dp:DataProvider = new DataProvider(); for(var i:int = 0 ; i < 7; i++) dp.addItem({label:'label '+(i+1), ID:Math.random()}); myDataGrid.dataProvider = dp;

如果您为CHANGE事件设置了处理程序,则应该能够通过selectedItem获取所需的数据:

myDataGrid.addEventListener(Event.CHANGE, changed); function changed(event:Event):void { trace('item at index ' + myDataGrid.selectedIndex + ' has ID: ' + myDataGrid.selectedItem.ID); }

HTH,乔治

Can you be a bit more specific ?

You can get get all the data you need from the DataGrid using the selectedItem.yourProperty. Can you post a snippet that might make thing clear ?

Referencing a column by name is pretty easy:

myDataGrid.getColumnAt(myDataGrid.getColumnIndex('ID'))

The data is in the DataGrid's dataProvider, the column is there for other purposes.

Say you have an ID property added to the DataGrid:

var dp:DataProvider = new DataProvider(); for(var i:int = 0 ; i < 7; i++) dp.addItem({label:'label '+(i+1), ID:Math.random()}); myDataGrid.dataProvider = dp;

If you have setup a handler for the CHANGE event, you should be able to get the data you need through the selectedItem:

myDataGrid.addEventListener(Event.CHANGE, changed); function changed(event:Event):void { trace('item at index ' + myDataGrid.selectedIndex + ' has ID: ' + myDataGrid.selectedItem.ID); }

HTH, George

更多推荐

本文发布于:2023-08-06 17:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1454259.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在特定   Datagrid   column   row   selected

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!