redoc01
redoc01

Reputation: 2307

Delete all rows in a DataGrid

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

Answers (3)

ToddBFisher
ToddBFisher

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

pho
pho

Reputation: 25489

Once you have removed the items you want from the datagrid's dataprovider, you should invalidate it using datagrid.invalidateList()

Upvotes: 1

Ronnie
Ronnie

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

Related Questions