AS2 moving a datagrid row up or down

I have attached a file as a sample, basically I want to select a row in a datagrid and move it up or down in the order using buttons outside the datagrid. I'm sure this is simple - but some how I'm not making it work.
move.fla
twall73Asked:
Who is Participating?
 
blue-genieConnect With a Mentor Commented:
0
 
blue-genieCommented:
hi i've uploaded a sample for you.


move-Bgi.fla
0
 
twall73Author Commented:
Sorry I guess I did not explain it very well. What I am trying to do is move the items in the row up or down, so that the datagrids row items are in a new order. ie if you select a row at index 1 and move it up the itemss in row index 1 becomes the items in row index 0 and the items in row index 0 becomes the items in row index 1.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
blue-genieCommented:
ah ok. what you need to do then is swap the order in your dataprovider,whether it's an array or xml or whatever, and then just refresh your data provider
0
 
twall73Author Commented:
so if I create an array from the data in the datagrid, how would I swop the order in the array?
0
 
blue-genieCommented:
i did a quick google search and came across this

http://stackoverflow.com/questions/2461582/what-is-the-easiest-way-to-swap-items-inside-an-array-actionscript-2-0


you basically need to swap the indexes around.
0
 
twall73Author Commented:
Provided a link to a solution on the internet over explaining it - still solved the problem but at Expert Exchange as a paying member I thought I would get an Expert answer!!!
0
 
blue-genieCommented:
I don't believe in re-inventing the wheel - remember the "experts" are all volunteers - for me it's about knowledge sharing - if there's a solution out there why should we re-type it here when the answer is already out there.
Also I could fake it and pretend that it's all me, but I believe in giving credit where credit is due i.e other people who've worked on something.
Not sure what you would consider an "Expert answer" - sorry to have let everyone down. Promise to try harder.
0
 
twall73Author Commented:
After doing a lot a trial and error I actually figured out how to achieve this:

function swapLines(a,b){
	var a_obj:Object = subs_dg.getItemAt(a);
	var b_obj:Object = subs_dg.getItemAt(b);
	
	subs_dg.removeItemAt(a); 
                     subs_dg.addItemAt(a, b_obj);
	
	subs_dg.removeItemAt(b); 
                     subs_dg.addItemAt(b, a_obj);	
};

Open in new window


I knew there must be a simple solution and there it is....
move.fla
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.