Convert Flex Datagrid results into a string


I've spent WAYY too many hours trying to figure this out, and about to pull my hair out. I have a Flex Datagrid that I'm trying to convert into a SIMPLE string. My function is the following:

A couple problems:

Problem #1 - When the datagrid converts to a string, the order of the items in my string are arranged in an adhoc manner. So for example if the first row of the datagrid contains the <First Name> , followed by the <Last Name>, followed by the <Age>, the iteration over obj2 doesn't stay in the <First Name> <Last Name> <Age> order...the order always spits out randomly! What is really interesting is that on different computers, the order changes, but on the same computer, the order doesn't change. Is there a better way to save the datagrid results to a string?

The second problem - When you iterate over obj2, there is this wierd binary string that comes out like 078285D5-7022-17BC-4EE3-98E93E8696A4

What sucks is that now that "078285D5-7022-17BC-4EE3-98E93E8696A4" is also added into my string. You'll notice that I've tried taking it out in my code but, it doesn't work all the time.

private var file:FileReference = new FileReference();
private var myString:String = new String
private var sTemp:String = new String
private var inti:Number
private var intCountDash:Number
private function ExporttoCSV():void{
myString = "Cost, Attribute, Change, PV, Level, ROI\r\n"
for each( var obj:Object in myData )
for each( var obj2:Object in obj )
intCountDash = 0;
var encr_int: Number=0;
for (inti=0; inti < String( obj2 ).length; inti++) 
if(String( obj2 ).charAt(inti) == '-') 
         						intCountDash = intCountDash + 1;
	  					if (sTemp != "")
							if (intCountDash !=4)
								if (String( obj2 ) == "&#8593;")
									sTemp += "," + "Increased from Current";
								if (String( obj2 ) == "&#8595;")
									sTemp += "," + "Decreased from Current";
								if (String( obj2 ) == "&#8596;")
									sTemp += "," + "No Change";
								if ((String( obj2 ) != "&#8593;") && (String( obj2 ) != "&#8595;") && (String( obj2 ) != "&#8596;"))
									sTemp += "," + String( obj2 )	
							sTemp = String( obj2 )
					myString += sTemp + "\r\n";
					sTemp = "";

                        //var test:String = "Hello World, By World"

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I see that you start your string by defining what the output will be, so you presumably know the exact columns in your data grid.  In that case, why go generic?
I would try something like this, starting at line 8:
myString = "Cost, Attribute, Change, PV, Level, ROI\r\n";
var costCol:DataGridColumn =  myData.columns[0];
var attrCol:DataGridColumn = myData.columns[1];
var changeCol:DataGridColumn = myData.columns[2];
var pvCol:DataGridColumn = myData.columns[3];
var levelCol:DataGridColumn = myData.columns[4];
var roiCol:DataGridColumn = myData.columns[5];

for (var i:int = 0; i < myData.rowCount; ++i)
    row:Object = myData.getItemAt( i );
    myString += costCol.itemToLabel( row ) + ", ";
    myString += attrCol.itemToLabel( row ) + ", ";
    myString += changeCol.itemToLabel( row ) + ", ";
    myString += pvCol.itemToLabel( row ) + ", ";
    myString += levelCol.itemToLabel( row ) + ", ";
    myString += roiCol.itemToLabel( row ) + "\r\n";
I haven't tested this code in any way, but it looks like it should work.
reference: for how to get any individual value from a cell.
Good luck!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
piyushdabombAuthor Commented:
I haven't tested this out, but I figured out how to go around it. Thanks a lot!

If I ever need this, I will use it. I was simply in a rush to finish my project.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.