Reputation: 2307
I need to delete all existing rows from a data grid, i have tried using this but doesn't work:
public function GetMusicList(obj:Object):void{
for(var j = 0; j < mc_music.datagrid.rowCount; j++){
mc_music.datagrid.dataProvider.removeItemAt(0);
}
for(var i = 0; i < obj.length; i++){
mc_music.datagrid.addItem({Name: obj[i].toString()});
}
}
Upvotes: 3
Views: 3330
Reputation: 11590
Additionally you can set the data provider of the data grid to a valid dataProvider with no data it in, but I would look into one of the other answers first as calling a pre-built method feels cleaner.
Upvotes: 1
Reputation: 25489
Once you have removed the items you want from the datagrid's dataprovider, you should invalidate it using datagrid.invalidateList()
Upvotes: 1
Reputation: 11198
Your title is asking a different question than your actual question, but to remove all the rows just do datagrid.removeAll();
Upvotes: 1