PDA

View Full Version : How to know the index of a row in the datagrid without selecting the row?


tanusree
09-12-2007, 02:16 PM
Basically I want to get the value of first column of every row of a datagrid.So, for this I have collect the rowCount of datagrid.But after that I don't know how to proceed?

So, how to get the index of every row & column without selecting any row?

Can anyone help me for this with code example.

drkstr
09-12-2007, 02:50 PM
for each( var row:Object in idDataGrid.dataProvider ) {
trace( row.columnProperty );
}


I think this is what you are looking for. Your question didn't really match the title, but this will allow you to access each item in a column. If you want to find the index of a particular row, you would loop through like shown, and increment an integer on every loop. Break when (row == search_row) and you have your index.

Hope this helps,
...aaron

*edit*
You may need to adjust the code depending on the data type of the dataProvider.

tanusree
09-13-2007, 10:36 AM
This code don't work.

I want to find out the index of every row & columnof a datagrid.

Can anyone help me?

drkstr
09-13-2007, 05:40 PM
Yes it does. You didn't do it correctly. You need to modify the syntax to match your specific application. Also, in the paragraph bellow the example, I explain how to get the index for each row.

Best regards,
...aaron

drkstr
09-13-2007, 08:24 PM
Ah, I just saw you want the column index too. This should work for that:


var r:int = 0;
var c:int = 0;
for each( var row:Object in idDataGrid.dataProvider ) {
c = 0;
for( var property:String in row ) {
trace(property);
trace( 'row='+r+', col='+c );
c++;
}
r++;
}


How you use the c and r values from there is up to you.

Regards,
...aaron

tanusree
09-24-2007, 12:41 PM
var r:int = 0;
var c:int = 0;
for each( var row:Object in idDataGrid.dataProvider )
{
c = 0;
for( var property:String in row )
{
trace(property);
trace( 'row='+r+', col='+c );
c++;
}
r++;
}


Using this I can get only the value stored in the first column of every row.
Now I want value of every column of every row.

Can anyone help me ragarding this problem with code example.

drkstr
09-24-2007, 03:25 PM
Huh, that's funny. It seems to work just fine for me:


row=0, col=0
amenities
row=0, col=1
date
row=0, col=2
rent
row=0, col=3
company
row=0, col=4
isFav
row=0, col=5
id
row=0, col=6
title
row=0, col=7
mx_internal_uid
row=1, col=0
amenities
row=1, col=1
date
row=1, col=2
rent
row=1, col=3
company
row=1, col=4
isFav
row=1, col=5
id
row=1, col=6
title
row=1, col=7
mx_internal_uid
row=2, col=0
amenities
row=2, col=1
date
row=2, col=2
rent
row=2, col=3
company
row=2, col=4
isFav
row=2, col=5
id
row=2, col=6
title
row=2, col=7
mx_internal_uid
row=3, col=0
amenities
row=3, col=1
date
row=3, col=2
rent
row=3, col=3
company
row=3, col=4
isFav
row=3, col=5
id
row=3, col=6
title
row=3, col=7


Perhaps you are doing something wrong then? If you post your code, we will be able to tell you what that is. Is your DataGrid created dynamicly? If not, you should know the column index already since you created them that way.

Best Regards,
...aaron