Setting cell values in DataGrid

I have an application with a custom component called DataEntryDataGrid (which is a subclass of mx:DataGrid) that I based on this blog post:  http://blogs.adobe.com/aharui/2008/03/custom_arraycollections_adding.html
The component works great, but in this particular datagrid I need some special functionality.   After the first row of data is entered and the user tabs into the next row, I need the first and second columns to be filled in based on the values of the previous row, and then I need it to automatically focus on the third column's cell.  While the first and second columns should be still editable, they will be largely repetitive, and it would help if the users didn't have to enter the same numbers again and again.  The first column in a new row should be the same value as the first column in the last row, and the second column in a new row should be (last row's value +1). Example:
DataGrid:
| Slide No. | Specimen No. | Age | Weight | Length |
|    1      |     1        |  5  |  65    |  40    |  <- This row is manually entered, just text inputs
|    1*     |     2*       |  #  |        |        |
* = values set programatically, these cells should still be focusable and editable
# = this is where the focus should be
The problem I'm having is that when I tab into the next row, the first column value doesn't get set.  The second column gets set to the correct value and displayed correctly, and the focus is set to the correct cell (the third column), but the first column remains empty.  I'm not sure why this is.  If I set a breakpoint in the code during the function focusNewRow()  (which is called at the dataGrid's "itemFocusIn" event)  the value of "slideNo" (first column) is set to the correct value, but after the "focusNewRow" functions finishes, a trace of dataProvider[the current row].slideNo shows the value is blank.  Not null, just blank.  Traces of all other columns show the correct values.  Anyone have any ideas?  Here's the code for my main application:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
         xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:components="components.*">
  <fx:Script>
    <![CDATA[
      import mx.controls.DataGrid;
      import mx.events.DataGridEvent;
      public function traceSlideNo():void {
        var i:int;
        var g:Object = myDataGrid.dataProvider;
        for(i = 0; i < g.length -1; i++) {
          trace("sl: " + g[i].slideNo + ", sp: " + g[i].specimenNo + ", age: " + g[i].age);
      public function focusNewRow(e:DataGridEvent):void {
        if(e.currentTarget.dataProvider.length > 0 && e.rowIndex != 0 && e.columnIndex == 0) {
          var dg:DataGrid = e.currentTarget as DataGrid;
          var lastItem:Object = dg.dataProvider[e.rowIndex - 1];
          var targetItem:Object = dg.dataProvider[e.rowIndex];
          if(targetItem.specimenNo == "") {
            var focusCell:Object = new Object();
            focusCell.rowIndex = e.rowIndex;
            focusCell.columnIndex = 2;
            dg.editedItemPosition = focusCell;
            targetItem.slideNo = int(lastItem.slideNo);
            targetItem.specimenNo = int(lastItem.specimenNo) + 1;
            callLater(dg.dataProvider.refresh);
    ]]>
  </fx:Script>
  <components:DataEntryDataGrid x="10" y="10" width="450" id="myDataGrid" itemFocusIn="focusNewRow(event)"
                  editable="true" rowHeight="25" variableRowHeight="false">
    <components:columns>
      <mx:DataGridColumn headerText="Slide No." dataField="slideNo" editable="true"/>
      <mx:DataGridColumn headerText="Specimen No." dataField="specimenNo" editable="true"/>
      <mx:DataGridColumn headerText="Age" dataField="age" editable="true"/>
      <mx:DataGridColumn headerText="Weight" dataField="weight" editable="true"/>
      <mx:DataGridColumn headerText="Length" dataField="length" editable="true"/>
    </components:columns>
  </components:DataEntryDataGrid>
  <s:Button x="10" y="195" label="Trace Slide Numbers" click="traceSlideNo()"/>
</s:Application>
And here's the custom component, DataEntryDataGrid, just for reference (placed in the "components" package in this example) :
<?xml version="1.0" encoding="utf-8"?>
<mx:DataGrid xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx" initialize="init(event)"
       editable="true" wordWrap="true" variableRowHeight="true">
  <fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
  </fx:Declarations>
  <fx:Script>
    <![CDATA[
      import components.NewEntryArrayCollection;
      import mx.controls.Alert;
      import mx.controls.dataGridClasses.DataGridColumn;
      import mx.events.DataGridEvent;
      import mx.events.DataGridEventReason;
      import mx.events.FlexEvent;
      import mx.utils.ObjectUtil;
      private var arr:Array = [];
      private var ac:NewEntryArrayCollection;
      private var dg:DataGrid;
      public var enableDeleteColumn:Boolean;
      private function generateObject():Object
        // Returns a new object to the datagrid with blank entries for all columns
        var obj:Object = new Object();
        for each(var item:Object in this.columns) {
          var df:String = item.dataField.toString();
          obj[df] = "";
        return obj;
      private function isObjectEmpty(obj:Object):Boolean
        // Checks to see if the current row is empty
        var hits:int = 0;
        for each(var item:Object in this.columns) {
          var df:String = item.dataField.toString();
          if(obj[df] != "" || obj[df] !== null) {
            hits++;
        if(hits > 0) {
          return false;
        return true;
      private function init(event:FlexEvent):void
        dg = this;                // Reference to the DataEntryDataGrid
        ac = new NewEntryArrayCollection(arr);  // DataProvider for this DataEntryDataGrid
        ac.factoryFunction = generateObject;
        ac.emptyTestFunction = isObjectEmpty;       
        dg.dataProvider = ac;
        // Renderer for the DELETE column and Delete Button Item Renderer
        if(enableDeleteColumn == true){
          var cols:Array = dg.columns;
          var delColumn:DataGridColumn = new DataGridColumn("del");
          delColumn.editable = false;
          delColumn.width = 35;
          delColumn.headerText = "DEL";
          delColumn.dataField = "delete";
          delColumn.itemRenderer = new ClassFactory(DeleteButton);
          cols.push(delColumn);
          dg.columns = cols;
          dg.addEventListener("deleteRow",deleteClickAccept);
      private function deleteClickAccept(event:Event):void { // Handles deletion of rows based on event dispatched from DeleteButton.mxml
        dg = this;
        ac = dg.dataProvider as NewEntryArrayCollection;
        if(dg.selectedIndex != ac.length - 1) {
          ac.removeItemAt(dg.selectedIndex);
          ac.refresh();
    ]]>
  </fx:Script>
</mx:DataGrid>
Also, the file NewEntryArrayCollection.as which is referenced by the custom component.  This also goes in the "components" package:
package components
  import mx.collections.ArrayCollection;
  public class NewEntryArrayCollection extends ArrayCollection
    private var newEntry:Object;
    // callback to generate a new entry
    public var factoryFunction:Function;
    // callback to test if an entry is empty and should be deleted
    public var emptyTestFunction:Function;
    public function NewEntryArrayCollection(source:Array)
      super(source);
    override public function getItemAt(index:int, prefetch:int=0):Object
      if (index < 0 || index >= length)
        throw new RangeError("invalid index", index);
      if (index < super.length)
        return super.getItemAt(index, prefetch);
      if (!newEntry)
        newEntry = factoryFunction();
      return newEntry;
    override public function get length():int
      return super.length + 1;
    override public function itemUpdated(item:Object, property:Object = null,
                       oldValue:Object = null,
                       newValue:Object = null):void
      super.itemUpdated(item, property, oldValue, newValue);
      if (item != newEntry)
        if (emptyTestFunction != null)
          if (emptyTestFunction(item))
            removeItemAt(getItemIndex(item));
      else
        if (emptyTestFunction != null)
          if (!emptyTestFunction(item))
            newEntry = null;
            addItemAt(item, length - 1);
Sorry for the length of this post, but I hate seeing people post without including enough information to solve the problem.  If there's anything I've left out, let me know.

Problem solved.  Actually, the NewEntryArrayCollection pointed to an outside function within the DataEntryDataGrid component to be used as a factory function for new objects.  I just set the factory function to scan the previous row's values and base the new row's values off of them.  Thanks again, Flex!
New private function generateObject() to replace the previous one in DataEntryDataGrid.mxml, just in case others are curious:
private function generateObject():Object
  // Returns a new object to the datagrid with filled in slide and
  // specimen no. columns and the rest of the columns blank
  var obj:Object = new Object();
  var thisDP:Object;
  for each(var item:Object in this.columns) {
    var df:String = item.dataField.toString();
    if(df == "slideNo") {
      thisDP = this.dataProvider;
      var newSlideNo:int;
      if(thisDP.length > 1) {
     // looking for the last row of the DataGrid's dataProvider, but as
        // length is calculated differently in NewEntryArrayCollection.as
        // to account for the "dummy" row, we need to go back 2 rows.
        newSlideNo = int(thisDP[thisDP.length -2].slideNo);
      } else {
        newSlideNo = 1;
      obj[df] = newSlideNo;
    } else if(df == "specimenNo") {
      thisDP = this.dataProvider;
      var newSpecimenNo:int;
      if(thisDP.length > 1) {
        newSpecimenNo = int(thisDP[thisDP.length -2].specimenNo) + 1;
      } else {
        newSpecimenNo = 1;
      obj[df] = newSpecimenNo;
    } else {
      obj[df] = "";
  return obj;

Similar Messages

  • Labview/excel: erreur -2147352567 dans Set Cell Value.vi

    Bonjour à tous,
    Je suis face à un problème insoluble.
    Je n'arrive plus à écrire dans une cellule excel.
    J'ai développé mon programme sous labview 2009 et fait des tests sur deux pc différents.
    Sur un, l'écriture cellule fonctionne  sur l'autre j'ai toujours l'erreur -2147352567 dans Set Cell Value.vi.
    J'ai changé de pc et je suis passé de XP à Seven, installé labview 2009, mon programme bloque toujours sur le vi Set Cell Value.
    Comment puis je solutionner mon problème? recompiler le programme?
    Tous vos retours seront les bienvenus.
    Cdlt
    Solved!
    Go to Solution.
    Attachments:
    test-ecrire-excel.pdf ‏139 KB
    essai_ecrire_excel.vi ‏29 KB

    Bjr à tous,
    Le problème vient des modes de compatibilités d'excel entre 2003 et 2007-2010.
    Vous ne pouvez pas gérer des fichiers en .xls ou .xlsx sur la même application.
    Cela peu fonctionner un temps mais cela ne dure pas.
    La solution ensuite est de convertir tous vos fichiers en extension .xlsx et tout rentre dans l'ordre.
    Tout ceci est la joie d'excel et des logiciels à licence.
    A+ pour un autre sujet de discussion.

  • How to get selected Cell value in datagrid?

    Hi guys, I have a datagrid that is editable. I was wondering if it's possible to retreive the cell value after user edits the single cell.
    My datagrid will trigger griditemEditorSessionSave event if users finish the editing, but I don't know how to get the new cell value.
    //script
    protected function dg_gridItemEditorSessionSaveHandler(event:GridItemEditorEvent):void
         //I can only get the columnIndex but not the value
          Alert.show (event.columnIndex);
    //mxml
    <s:DataGrid id="dg" editable="true" x="5" y="3" width="734" height="153"
                      gridItemEditorSessionSave="dg_gridItemEditorSessionSaveHandler(event)"
    >
    </Datagrid>
    Any thoughts? Thanks a lot.

    Hi,
    Please go through following link :
    http://corlan.org/2008/08/31/retrieving-the-new-values-while-editing-data-inside-the-data- grids/
    Hope it helps you
    Thanks and Regards,
    Vibhuti Gosavi | [email protected] | www.infocepts.com

  • Set cell value performance...

    Hi,
    I'm trying to find out if any of you have a faster way of setting values in Matrix as for any System cell value like ItemCode, not just UDF's
    My actual code looks like that but I'm wondering if there's a faster way as right now, it is slow and having to set multiple values in matrix makes the addon very slow and unacceptable by customers
    public static object SetCellValue(SAPbouiCOM.Matrix Matrix, object ColumnUID, int Row, object Value)
        SAPbouiCOM.Column Column = Matrix.Columns.Item(ColumnUID);
        SAPError = "";
        object Cell = null;
        switch (Column.Type)
            case (SAPbouiCOM.BoFormItemTypes.it_EDIT):
            case (SAPbouiCOM.BoFormItemTypes.it_EXTEDIT):
            case (SAPbouiCOM.BoFormItemTypes.it_LINKED_BUTTON):
                SAPbouiCOM.EditText Editor = (SAPbouiCOM.EditText)Column.Cells.Item(Row).Specific;
                Cell = Editor;
                Editor.Value = Value.ToString();
                break;
            case (SAPbouiCOM.BoFormItemTypes.it_COMBO_BOX):
                SAPbouiCOM.ComboBox ComboBox = (SAPbouiCOM.ComboBox)Column.Cells.Item(Row).Specific;
                Cell = ComboBox;
                ComboBox.Select(Value, SAPbouiCOM.BoSearchKey.psk_ByDescription);
                break;
            case (SAPbouiCOM.BoFormItemTypes.it_CHECK_BOX):
                SAPbouiCOM.CheckBox chk = (SAPbouiCOM.CheckBox)Column.Cells.Item(Row).Specific;
                Cell = chk;
                chk.Checked = bool.Parse(Value.ToString());
                break;
        return Cell;

    Hi Marc,
    The new method GetCellSpecific of the matrix object is much faster than casting a cell to a particular control type using its Specific property:
    SAPbouiCOM.EditText Editor = (SAPbouiCOM.EditText)Matrix.GetCellSpecific(ColumnUID, Row);
    This should be noticeably faster than the older method and works for system matrices as well as user-defined ones.
    Kind Regards,
    Owen

  • Numbers set cell value

    Hi Guys, might be a weird question but here goes.
    am trying to create a formula that sets the values of other cells
    meaning:
    if A1 = 2
    in B1 i will put: =IF(A1=2,C1=2,D1=0) which will check if cell A1 has the value of 2 and if so put the value 2 in cell C1 and if not will put the value of 0 in D1.
    is that possible in numbers?
    is there a way to do the same but with 2 cells changed at the same time?
    meaning:
    =IF(A1=2,C1=2 AND D1=2,D1=0)
    thanks
    ben

    Hi Hubert (Ben),
    A formula can not put a value into another cell.
    Try this:
    B2 =IF(A2=2,2,0) and fill down
    In English:
    IF A2 is equal to 2, then make me (B2) equal to 2, else make me equal to 0
    To test for several conditions in the one formula, use one IF inside another (nested IFs), or use the AND() function.
    Have a look at the Function Browser on the toolbar in Numbers.
    Also the Numbers User Guide and the Formulas and Functions User Guide available from the Help Menu in Numbers
    Regards,
    Ian.

  • To set a value in matrix cell which is linked

    In sales order if I enter  form no of TAX TAB as "form c" , each cell of the TAX Code column of the matrix of contents tab should be set the value as "CST". I have tried to set the value, but it is showing "Form item not editable". I have tried to make the cell as editable but still the error message is coming and it is not setting the defined value. How can this be solved?
    Thankx in advance

    Hi Priya Manoj
    Some notes you can find on this [Thread: Set Value in Itemcode in Purchase Order Form|Set Value in Itemcode in Purchase Order Form;.
    There are I has posted some examples in vbcode.
    Hope the notes can help you.
    Regards
    Sierdna S.
    Edited by: Sierdna S on Oct 22, 2008 9:45 AM

  • How to enter a value into datagrid cell in wpf through manually?

    Hi,
        Here my datagrid rows are in readonly mode here how can i enter the values in to the datagrid cell.(means how can i edit the cell value).i am adding the value to datagrid through programetically, I think  for this reason my datagrid rows
    are visible in readonly mode. Then how can i edit. Please guide me.
    Regards,
    Bhadram

    Hi Barry,
       Thank you for your reply, Now i sending my sample please check it once and suggest me.
    MainWindow.xaml.cs
    private void Save_Click(object sender, RoutedEventArgs e)
     List<CustomerMainViewModel> customer = new List<CustomerMainViewModel>(); customerviewmodel.NameTextField = tbName.Text;
    customerviewmodel.AddressTextField = tbAddress.Text;
    customerviewmodel.CountryField = countryddl.Text;
    customerviewmodel.StateField = stateddl.Text;
    customerviewmodel.Product = customerviewmodel.Product1 + "," + customerviewmodel.Product2;
    foreach(string str in customerviewmodel.actionCollection)
    customerviewmodel.ActionColl.Add(str);
    customerviewmodel.actionCollection.Clear();
    customer.Add(customerviewmodel);
    dataGrid1.Items.Add(customer);
    MessageBox.Show("Data Successfully Saved", " MessageBox", MessageBoxButton.OK, MessageBoxImage.Asterisk);
    clearValues();
    MainWindow.xaml
    <DataGrid
    Height="144"
    HorizontalAlignment="Left"
    Margin="79,447,0,0"
    Name="dataGrid1"
    VerticalAlignment="Top" CanUserAddRows="True"
    Width="399" Grid.RowSpan="2" IsReadOnly="False">
    <DataGrid.Columns>
    <DataGridTextColumn Header="NAME" Binding="{Binding NameTextField,Mode=TwoWay}" Width="Auto" IsReadOnly="False" />
    <DataGridTextColumn Header="ADDRESS" Binding="{Binding AddressTextField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="GENDER" Binding="{Binding GenderField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="COUNTRY" Binding="{Binding CountryField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="STATE" Binding="{Binding StateField,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTextColumn Header="PRODUCT" Binding="{Binding Product,Mode=TwoWay}" Width="Auto" IsReadOnly="False"/>
    <DataGridTemplateColumn Header="ACTION" MinWidth="140" IsReadOnly="False">
    <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
    <ComboBox x:Name="actionddl" ItemsSource="{Binding ActionColl}"/>
    </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    </DataGrid.Columns>
    </DataGrid>
    In the above "xaml" file i am using the attribute "Readonly="False"" but its not effected on my code still my datagrid is in readonly mode, i don't know why it happens. 
    And I am adding data to my datagrid through "Wpf controls (TextBox,CheckBox,ComboBox and etc...)"  while click on "save" button the data added to grid. adding to grid works properly but the entire row is in readonly mode. How can
    i solve my problem.  

  • How to set default value and bg color of cross tab cell?

    Hi all
    Which way can I set default value and background color for a crosstab cell where there are no any data?
    I try to pass it in following way
    if isnull(CurrentFieldValue) then
    But is has no effect.

    Hi,
    If your field is numeric
    if currentfieldvalue =0 then cryellow else crnocolor
    if the field is numeric but you don't see the 0 check check if : Suppress if zero is ticked in the Number format tab.
    Regards

  • Iam using a table in numbers to plot daily graph lines. If I fill a cell with a text box  at say zero it plots the graph. I can't actually set the cell value until the actual day but the graph plots it at zero when I don't want it to plot anything. Is tho

    I am using a table in Numbers to plot daily graph lines. Mood swings of how I am on the day, i"m a depressive.
    If I fill a cell with a step box at say zero it plots the graph. I can't actually set the cell value until the actual day but the graph plots it at zero when I don't want it to plot anything. Is there a work around. so thatbgraph only plots on the day?

    The answer is (sort of) in your subject, but edited out of the problem statement in the body of your message.
    When you use a stepper or a slider, the value in the cell is always numeric, and is always placed on the chart if that cell is included in the range graphed by the chart.
    But if you use a pop-up menu cell, you can specify numeric or text values in the list of choices for in the menu. Numeric values will be shown on the chart. Text values will not.
    For the example, the values list for the pop-up menu was:
    5
    3
    1
    Choose
    -1
    -3
    -5
    The first pop-up was set to display Choose, then the cell was filled down the rest of the column. Any text value (including a single space, if you want the cell to appear blank) may be used instead of Choose.
    For charts with negative Y values, the X axis will not automatically appear at Y=0. If your value set will include negative values, I would suggest setting the Y axis maximum and minimum to the maximum and minimum values on your menu list, rather than letting Numbers decide what range to include on the chart. Place a line shape across the chart at the zero level, and choose to NOT show the X axis.
    Regards,
    Barry

  • Tables - How to get cell value? How to get/set UI controls properties?

    Hi,
    I want to get a the cell's value of row x and col y.
    The table is not bounded so I cannot use:
    Table1.Items(key).DataSourceRow.DataItem("ColID")
    Another question:
    How to I set the properties of a table column which contains UI elemtents that I create dynamically?
    for exmpale:
    c1 is a TableBodyCell
    tr is a tableRow
    c1 = New TableBodyCell(Table1, tr, 0)
    c1.TableCellContent = New InputField
    tr.Cells.Add(c1)
    How do I set/get the properties of the InputField?
    Thanks,
    Omri

    Thanks Reshef,
    My Table's scheme:
    Column 0 - TextView
    Column 1 - InputField
    I was able to get a cell value of type TextView by using what you suggested:
    Write(CType(Table1.Items(0).Cells(0).TableCellContent,TextView).Text)
    However, when I tried to do the exact thing to InputField I didn't get any value (nor error)
    Write(CType(Table1.Items(0).Cells(1).TableCellContent, InputField).Value)
    I fill the Input Field and then push "Execute" button which supposed to write the value.
    About my second question:
    By using the cast (CType) I can access the properties I need (like Width) so it kind of solve my problem.
    for example:
    CType(Table1.Items(1).Cells(1).TableCellContent, InputField).Width = "15px"

  • Permanently set Repeat cell values on table view obiee11g

    Hi,
    By default Analysis presentation Column comes with "Column Value Suppression" but we need to switch "Column Value Suppression" to "Repeat cell values" from source xml reference file
    Note:don't want to do it via analysis table/column properties(its manual work) ..just looking to change permanently by changing xml
    Thanks
    Deva

    Hi,
    What is that datatypeformats.xml ? couldn't find out. once again will explain my requirement
    Creating new analysis(Table/Pivot table view) and applying format as Repeat Cell by changing Table/Pivot Properties to set Enable alternating row "green bar" styling Repeat cell values on table/pivot view (instead of doing manual way)
    Refer the below image --> i just want to avoid manual enabling below Repeat cell option for entire table/pivot view option
    http://i.imgur.com/122wp.jpg?1
    Thanks
    Deva
    Edited by: Devarasu on Nov 26, 2012 5:06 PM

  • How to set ADF table cell value in managed bean

    Hi all,
    I have an ADF table on my page, let's assume with three columns with Input text box: col A, col B and col C where column C is hidden, when I click on Submit is possible to set in managed bean the value of column C for each rows?
    Thk in advance.
    L-

    Hi,
    you can create a button with an ActionListener. In the ActionListener you can iterate over the rows (using the iterator) and set the value on the attribute. If you need to save the changes you can call the commit operation binding.
    Linda

  • Custom itemRenderer component based on cell value: error 1009

    I'm working on an item renderer for a dataGrid that has different states depending on the cell and row values.
    The cell value is a toggle (true or null), and sets whether content should be shown in the cell or not
    The row properties determine what is shown when the cell value is true.
    The dataGrid dataProvider is populated based on user id input.
    I created the itemRenderer as a custom actionscript component, closely following this example:
    360Flex Sample: Implementing IDropInListItemRenderer to create a reusable itemRenderer
    However, my component results in Error #1009 (Cannot access a property or method of a null object reference) when a user id is submitted.
    package components
         import mx.containers.VBox;
         import mx.controls.*;     import mx.controls.dataGridClasses.DataGridListData;
         import mx.controls.listClasses.BaseListData;
         import mx.core.*;
         public class toggleCellRenderer extends VBox
              public function ToggleCellRenderer()
              {super();}
              private var _listData:BaseListData;   
                   private var cellState:String;
                   private var cellIcon:Image;
                   private var imagePath:String;
                   private var imageHeight:int;
                   private var qty:String = data.qtyPerTime;
                   private var typ:String = data.type;
              public function get listData():BaseListData
                   {return _listData;}
              public function set listData(value:BaseListData):void
                   {_listData = value;}
              override public function set data(value:Object):void {
                   super.data = value;
                   if (value != null)
                   //errors on next line: Error #1009: Cannot access a property or method of a null object reference.
                   {cellState = value[DataGridListData(_listData).dataField]}
              override protected function createChildren():void {
                   removeAllChildren();
                   if(cellState=='true'){
                        cellIcon = new Image();
                        addChild(cellIcon);
                   //there is another state here that adds another child...
              //next overrides commitProperties()...
    There are no errors if I don't use an itemRenderer--the cells correctly toggle between "true" and empty when clicked.
    I also tried a simple itemRenderer component that disregards the cell value and shows in image based off row data--this works fine without errors or crashing. But I need to tie it to the cell value!
    I have very limited experience programming, in Flex or any other language. Any help would be appreciated.

    Your assumption that the xml file either loads with "true" or nothing  is right.
    After modifying the code to the following, I don't get the error, but it's still not reading the cell value correctly.
    package components
         import mx.containers.VBox;
         import mx.controls.*;   
         import mx.controls.dataGridClasses.DataGridListData;
         import mx.controls.listClasses.BaseListData;
         import mx.core.*;
         public class toggleCellRenderer extends VBox
              public function ToggleCellRenderer()
               super();
              private var _listData:BaseListData;   
              private var cellState:Boolean;
              private var cellIcon:Image;
              private var imagePath:String;
              private var imageHeight:int;
              private var qty:String;
              private var typ:String;
               public function get listData():BaseListData
                 return _listData;
              override public function set data(value:Object):void {
                   cellState = false;
                   if (listData && listData is DataGridListData && DataGridListData(listData).dataField != null){
                       super.data = value;
                       if (value[DataGridListData(this.listData).dataField] == "true"){
                           cellState = true;
              override protected function createChildren():void {
                   removeAllChildren();
                   if(cellState==true){
                        cellIcon = new Image();
                        addChild(cellIcon);
                   //there is another state here that adds another child...
              //next overrides commitProperties()...
    - didn't set the value of qty or typ in the variable declarations (error 1009 by this too--I removed this before but wanted to point out in case its useful)
    - added back in the get listData() function so I could use the listData
    - changed the null check
    All cells are still returning cellState = false when some are set to true, even if I comment out [if (value[DataGridListData(this.listData).dataField] == "true")] and just have it look for non-null data. That shouldn't make a difference anyway, but it confirms that all cells are returning null value.
    Swapping out the first if statement in set data with different variables results in the following:
    [if (listData != null)]  all cells return null (cellState=false for all)
    both [if (value != null)] and  [if (DataGridListData != null)]  results in error 1009 on a line following the if, so I assume they return non-null values.
    All rows have data, just not all fields in all rows, so shouldn't listData be non-null?  Could it be that the xml file hasn't fully loaded before the itemRenderer kicks in?
    I also realized  I had removed the item renderer from many of the columns for testing, and since some columns are hidden by default only one column in the view was using the itemRenderer--hence the single alert per row I was worried about earlier.
    Thanks for your help so far.

  • Update cell Sprite in DataGrid

    Hi,
    I have a datagrid with a LOT of sprites (1700 circles, squares, and triangles) that I created in an itemRenderer in Actionscript using Peter Ent's excellent tutorial on custom item renderers. http://www.adobe.com/devnet/flex/articles/itemrenderers_pt5_03.html. Therefore, the Sprites inherit from UIComponent.
    I need to dynamically update a few of these sprites based on new data I pull down from the server once per minute.
    A full-page refresh is to be avoided since it takes 3-4 seconds to load and is disruptive to the user experience.
    Getting the row/column # from the datagrid's itemClick event is dead simple, but I don't see my Sprite when I look at the data using the debugger.
    What is the syntax to retrieve a given cell's Sprite from the application? Also, once I have that Sprite, how do I update/replace a Sprite only in that cell?
    Please help.
    Thanks!!!

    You're right, it isn't adding rows.
    I'm not sure what you mean by 'all the sprites are chosen based on the data  object and that old existing sprites get removed or re-purposed'.
    I have 3 grids, but for the sake of simplicity will focus on just 1.
    There are 39 rows and 15 columns. Each has a Sprite. At the moment, each column has its own custom ItemRenderer since there are data tags unique to each. I've noticed that the whole Object is passed in, so I *could* have one ginormous class to create Sprites for all 15 columns of a row at once, but (1) it didn't work to put that ItemRenderer at the datagrid level versus the individual column level and (2) I'm not sure which is more efficient.
    Anyway, back to the most pressing problem: how to update Sprites in the grid from data updates.
    Here is the code for the custom Item Renderer:
    package utilities
         import flash.display.Sprite;
         import mx.controls.ToolTip;
         import mx.controls.listClasses.IListItemRenderer;
         import mx.core.UIComponent;
         import mx.events.FlexEvent;
         public class Drop1Renderer extends UIComponent implements IListItemRenderer
              public function Drop1Renderer()
                   super();
                   height=20;
                   width=16;
              // Internal variable for property
              private var _data:Object;
              // Make it bindable
              [Bindable("dataChange")]
              // Define the getter
              public function get data():Object
                   return _data;
              //define the setter
              public function set data(value:Object):void
                   _data = value;
                   invalidateProperties();
                   dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
                   if (value.deviceType1 != "Null")
                        var mySprite:Sprite = new Sprite();
                        mySprite.cacheAsBitmap=false;
                        buttonMode=true;
                        var uic:UIComponent = new UIComponent();
                        mySprite.graphics.beginFill(value.deviceColor1);
                        var triangleHeight:Number = 12;
                        switch (value.deviceType1)
                             case "Circle":
                                  mySprite.graphics.lineStyle(1,0x000000, .5);
                                  mySprite.graphics.drawCircle(8, 9, 5);
                                  break;
                             case "CircleBlue":
                                  mySprite.graphics.lineStyle(2,0x0000DD, .9);
                                  mySprite.graphics.drawCircle(8, 9, 5);
                                  break;
                             case "TriangleRed":
                                  mySprite.graphics.lineStyle(2,0xFF0000, .9);
                                  mySprite.graphics.moveTo((triangleHeight/2)+2, 3);
                                  mySprite.graphics.lineTo(triangleHeight+2, triangleHeight+1);
                                  mySprite.graphics.lineTo(2, triangleHeight+1);
                                  mySprite.graphics.lineTo((triangleHeight/2)+2, 3);
                                  break;
                             case "Triangle":
                                  mySprite.graphics.lineStyle(1,0x000000, .5);
                                  mySprite.graphics.moveTo((triangleHeight/2)+2, 3);
                                  mySprite.graphics.lineTo(triangleHeight+2, triangleHeight+1);
                                  mySprite.graphics.lineTo(2, triangleHeight+1);
                                  mySprite.graphics.lineTo((triangleHeight/2)+2, 3);
                                  break;
                             case "TriangleBlue":
                                  mySprite.graphics.lineStyle(2,0x0000DD, .9);
                                  mySprite.graphics.moveTo((triangleHeight/2)+2, 3);
                                  mySprite.graphics.lineTo(triangleHeight+2, triangleHeight+1);
                                  mySprite.graphics.lineTo(2, triangleHeight+1);
                                  mySprite.graphics.lineTo((triangleHeight/2)+2, 3);
                                  break;
                             case "Rect":
                                  mySprite.graphics.lineStyle(1,0x000000, .5);
                                  mySprite.graphics.drawRect(3, 4, 10, 10);
                                  break;
                             case "RectBlue":
                                  mySprite.graphics.lineStyle(2,0x0000DD, .9);
                                  mySprite.graphics.drawRect(3, 4, 10, 10);
                                  break;
                             case "RectOrange":
                                  mySprite.graphics.lineStyle(2,0xFFA500, .9);
                                  mySprite.graphics.drawRect(3, 4, 10, 10);
                                  break;
                             case "Ellipse":
                                  mySprite.graphics.lineStyle(1,0x000000, .7);
                                  mySprite.graphics.drawEllipse(2, 5, 12, 6);
                                  break;
                             default:
                                  mySprite.graphics.drawCircle(8, 9, 5);
                        uic.addChild(mySprite);
                        this.addChild(uic);
                        uic.toolTip = "Howdy there!";
              override protected function createChildren() : void
                   super.createChildren();
              override protected function commitProperties() : void
                   super.commitProperties();
              override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
                   super.updateDisplayList(unscaledWidth, unscaledHeight);

  • Get Current Selected Cell Value in an af:table

    Using JDeveloper 11.1.1.3.0
    I currently have a requirement where i need to call a server method and pass the value of the current selected Cell value in my af:table.
    The reason why i can't just make use of the currentSelectedRow is because i have a set of Columns (NumericValue1,NumericValue12,...NumericValue1n) and my server method can't really tell which cell i picked.
    So far, what i did is that i utilized F. Nimphius's article about using contextMenu and passing a clientAttribute.
    Re: How to pass parameter to inline popup when mouse over
    I'm hoping to do the same thing but without raising a popup on right click. So basically, i'm hoping to select an outputText in the table and this value will be stored in a pageFlowScopeBean.
    Has anybody encountered something similar?
    Thanks.

    Hi Barbara,
    You're aproach sounds intersting.
    So you mean to say, i'll create a component which has a bindings to my pageDefinition which needs to have it's clientComponent attribute set to true i believe so that my javascript can find this component.
    Then, i'll write a javascript that handles the focus event which then stores the clientAttribute value and stores that in the hidden component mentioned earlier. I'm guessing that once i set the newValue to the hidden component, it should be posted to the pageDef bindings upon hitting server side calls.
    I'll try this out and give an update on it.

Maybe you are looking for

  • Applying patch 10.2.0.5

    Hello, We are using OWB Repository 10.2.0.1 OWB Client 10.2.0.1.31 We would like to apply patch 10.2.0.5. Can we only patch the client or do we also need to patch the repository? Kind Regards, Dennis

  • Java.lang.VerifyError

    I've seen this error twice now and am wondering if anyone can help me           resolve it. The first time I saw it was with a servlet. When I moved           the servlet out of the servlet class path and put it the weblogic system           class pa

  • Illustrator 14.0.0 CS4 freezes on start up loading plugins on OSX10.10

    What is the problem. Started after a fresh 10.10 install and restore from backup. Software was working previously. Also at times i get error of Photoshopimport.aip and Photoshop.export.aip, but not all the time do i get the error but it always freeze

  • Radio Button Selection gives "The page cannot be found" Error

    I have a Radio Button that has 4 chooses, one of the choices has Javascript to ask a Prompt and uncheck it depending on the user response. When I select the one that has the prompt, it works as expected with the question, however when I click the Sub

  • My video dims randomly for no reason - can't reset

    I have an iMac G5 20" second generation... my problem is that my video display will randomly dim for no reason. In my settings, I do not allow it to go to sleep, display is not allowed to go to sleep, under options tab, Automatically reduce the brigh