Http://www.cflex.net/showfiledetails.cfm? Channelid = 1 & object = file & objectid = 735
Sometimes, we need to display the row number of the current row in the DataGrid control. If the database Source of the DataGrid (dataprovider) is a collection, the problem will be handled, you only need to add a virtual computing column to the DataGrid and customize the labelfunction of the column, in this function, call getitemindex to calculate the index of the current row and Add 1 to it and then return it as a character. Note: These row numbers are dynamically generated and always in a certain order, and it has no relationship with the sorting of other columns. If you want the row number to change with the change of the row (usually when sorting a column ), then you need to re-allocate the row number for all rows, which must be controlled by a program in dataprovider. The sample code is as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute"
Creationcomplete = "initapp ()">
<Mx: SCRIPT> <! [CDATA [
Import MX. Collections. arraycollection;
Import MX. Controls. Alert;
[Bindable] private VaR _ ACDP: arraycollection;
Public Function initapp (): void
{
VaR oitem: object;
_ ACDP = new arraycollection ();
Oitem = {album: "the lost chord", Artist: "The Moody Blues", price: "15.99 "};
_ ACDP. additem (oitem );
Oitem = {album: "Meddle", Artist: "Pink Floyd", price: "17.99 "};
_ ACDP. additem (oitem );
Oitem = {album: "Trespass", Artist: "Genesis", price: "18.99 "};
_ ACDP. additem (oitem );
} // Initapp
Private function lfrownum (oitem: object, icol: INT): String
{
VaR iindex: Int = _ ACDP. getitemindex (oitem) + 1;
Return string (iindex );
}
]> </MX: SCRIPT>
<Mx: vbox>
<Mx: DataGrid id = "dgsource" dataprovider = "{_ ACDP }"
Editable = "true">
<Mx: columns>
<Mx: array>
<Mx: datagridcolumn headertext = "Row #" labelfunction = "lfrownum"/>
<Mx: datagridcolumn headertext = "album" datafield = "album"/>
<Mx: datagridcolumn headertext = "artist" datafield = "artist"/>
<Mx: datagridcolumn headertext = "price" datafield = "price"/>
</MX: array>
</MX: columns>
</MX: DataGrid>
</MX: vbox>
</MX: Application>
Null