Solved

how can I move a datagrid row up or down in as3

Posted on 2008-10-20
7
902 Views
Last Modified: 2013-11-11
I am fairly new to AS3 and I need to find a way to move a datagrid row up and down in the datagrid order using buttons.  So far I have only managed to change which row is selected by altering datergrid.selectedIndex.
0
Comment
Question by:Susurrus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 39

Expert Comment

by:blue-genie
ID: 22764720
i'm gonna have a go at this cause i'm curious.
where are you thinking the buttons will be relative to the datagrid. not inside i hope.
0
 
LVL 39

Expert Comment

by:blue-genie
ID: 22764944
how are you populating your datagrid, and how are you envisioning the moving thing?
i.e currently i got it to a state when i click the 3rd row for example, and click move up. it moves to the 2nd row and the item that was in the 2nd row moves to the 3rd row.

where you thinking that - or must everything move 1 up and the first item becomes last?
i'll await your response then tidy up the code and post it.
0
 

Author Comment

by:Susurrus
ID: 22765419
Hi blue-genie, you have the right idea.  When a button outside the datagrid is clicked I want the rows to move exactly as you describe ("when i click the 3rd row for example, and click move up. it moves to the 2nd row and the item that was in the 2nd row moves to the 3rd row").

I am populating the datagrid with an array.  I have included the content of my datagrid populating function below.
import fl.controls.DataGrid;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.data.DataProvider;
 
var mediaarray:Array = new Array(
new Array("1", "flower", "jpg"),
new Array("2", "badger", "wmv"),
new Array("3", "car", "swf"),
new Array("4", "mouse", "jpg"),
new Array("5", "tree", "jpg"),
new Array("6", "dog", "jpg"),
new Array("7", "bin", "swf"),
new Array("8", "loud speaker", "wmv"),
new Array("9", "fridge", "swf"),
new Array("10", "tick", "swf"),
new Array("11", "wadders", "wmv"),
new Array("12", "kid", "jpg"));
 
var dp:DataProvider = new DataProvider();
 
for (var i:Number = 0; i < mediaarray.length; i++) {
	var position:String = mediaarray[i][0];
	var fileName:String = mediaarray[i][1];
	var type:String = mediaarray[i][2];
 
	dp.addItem({Position:position, Name:fileName,Type:type});
} 
 
var positionCol:DataGridColumn = new DataGridColumn("Position");
var fileNameCol:DataGridColumn = new DataGridColumn("Name");
var typeCol:DataGridColumn = new DataGridColumn("Tata");
	
positionCol.width = 35;
fileNameCol.width = 124;
typeCol.width = 40;
 
myDataGrid.addColumn(positionCol);
myDataGrid.addColumn(fileNameCol);
myDataGrid.addColumn(typeCol);
myDataGrid.dataProvider = dp;
myDataGrid.rowHeight = 30;

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Expert Comment

by:blue-genie
ID: 22765605
ok, i've just got to finish up some stuff for a client for a meeting tomorrow, i managed to get it to work, though it might be a tad messy. will clean it up and post it either tomorrow night or sometime then.
0
 

Author Comment

by:Susurrus
ID: 22765613
thanks very much for your help!
0
 
LVL 39

Accepted Solution

by:
blue-genie earned 500 total points
ID: 22774196
hi, have a look at the attached file.
i've added my code on top of yours. you'll see //blue-genie where i've made changes to your code.
i've just done some random testing and basic error checking, you can elaborate on that if you want.
shout if anything doesn't make sense.
Q-23828989.fla.txt
0
 

Author Comment

by:Susurrus
ID: 22780723
exactly what I needed.  Looks great!  thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question