Datagrid selected row at a certain column as3

自古美人都是妖i 提交于 2019-12-25 01:29:42

问题


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...


回答1:


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



来源:https://stackoverflow.com/questions/2096617/datagrid-selected-row-at-a-certain-column-as3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!