2 Replies Latest reply on Aug 23, 2011 12:29 AM by asdf1984

    get cell value programatically from DataGrid doesn't work

    asdf1984

      Hi, I would like to get cell value from datagrid, for example cell[3,4] = value from row 3, column 4. I found this code, which works (almost) perfectly:

       

      private function getCellValue(event:ListEvent):void {
                      // Get the target of this event (Datagrid)
                      var dataGrid:DataGrid = event.target as DataGrid;
                      // Get selected column index
                      var dsColumnIndex:Number = event.columnIndex;
                      // Get the DataGridColumn object to get the selected column name
                      var col:DataGridColumn = dataGrid.columns[dsColumnIndex];
                      // Get selected cell value from the selected row and column name
                      var cellValue:String = dataGrid.selectedItem[col.dataField];
                      Alert.show(cellValue);
                  }
                 
      ...

       

                  <mx:DataGrid width="100%" dataProvider="{browseItems}" doubleClickEnabled="true" itemDoubleClick="getCellValue(event)">
                      <mx:columns>
                          <mx:DataGridColumn headerText="First name" dataField="firstname"/>
                          <mx:DataGridColumn headerText="Last name" dataField="lastname"/>                   
                          <mx:DataGridColumn headerText="Person type" dataField="personType.code"/>
                      </mx:columns>
                  </mx:DataGrid>
                 
      When u double click on datagrid, it shows u value of cell u clicked. Everything is ok, BUT it works only for primitive types or direct object attributes. When i click on a cell, which contains some object (association to other object) - for example 3rd column Person type which contains object PersonType from which i'm only displaying attribute code - it doesnt work - i can't get value of field like this. I can see value in datagird, but it's not possible to programatically get this value, or I don't know how to do it. Other columns works ok. Any suggestions? Thx for help