views:

21

answers:

2

Any idea how to set value at a cell level in a data grid

I used the following

private function dataPanel(rowindex:Number, Var1:Number, Var1Name:String, Var2:Number, Var2Name:String, Var3:Number, Var3Name:String, Var4:Number, Var4Name:String): void { trace("rowindex ", rowindex)

if (rowindex==0) {

                col1.headerText=Var1Name;

                col2.headerText=Var2Name;

                col3.headerText=Var3Name;

                col4.headerText=Var4Name;
            } else {

            col1[rowindex].valueOf()=Var1;

            col2[rowindex].valueOf()=Var2;

            col3[rowindex].valueOf()=Var3;

            col4[rowindex].valueOf()=Var4;
            }   
        }

col1,col2, col3, col4 are id's for the 4 columns in data grid rowindex increments for value in each row...

it compiles and i get an error- it gets a strange error when i try to assign col1[]. how do i achieve this?

A: 

Use the dataField property

       <mx:DataGrid id="dg" width="100%" height="100%" rowCount="5" dataProvider="{employees}">
            <mx:columns>
                <mx:DataGridColumn dataField="Var1" headerText="Var1Name"/>
                <mx:DataGridColumn dataField="Var1" headerText="Var1Name"/>
                <mx:DataGridColumn dataField="Var1" headerText="Var1Name"/>
            </mx:columns>
        </mx:DataGrid>
Adrian Pirvulescu
Adrian- looks like we lost some messages. My need is to be able to set the variables in a dynamic setting- some level of user input/ processing. I tried using advancedDataGrid but get similar issues.
raghu
tried this rowcontents(which has been set as array) = AdvDataGrid.selectedCells({rowIndex:1,columnIndex:1},{rowIndex:1,columnIndex:4})... get this error "Attempted access of inaccessible method selectedCells through a reference with static type mx.controls:AdvancedDataGrid."
raghu
raghu
I am not sure how you can achieve that... because only the "visible" rows can be accessed. The flex datagrid component does not create a view-row for all rows in your array dataprovider, it creates just the visible ones.. ! good luck with it!
Adrian Pirvulescu
ok- any other way i can achieve using datagrid or anything else in Flex... essentially I need to till a 10 row, 4 c olumn table dynamically- hence need to build in ActionScript
raghu
Raghu: what is the exact use case of this implementation. Maybe you can achieve this with list or somehow dynamic creating elements of other type than using DataGrid.
Adrian Pirvulescu
A: 

I figured out the answer from an offline source. You set the datagrid to get values from an arraycollection, and populate values in the arraycollection.

I can share more detail if anyone needs...

raghu