Professional Web Applications Themes

Cell Focus after adding a new DataGrid item - Macromedia Flex General Discussion

I am trying to add a new item to a datagrid instance and then set focus to the first cell of the new record. There appears to be a sequencing error that is keeping the cell from retaining focus in doing this. What is very strange is that the cell focus works if there are enough items in the grid to have a vertical scroll bar visible, but it will not otherwise. Below is the code I am using in this process: dg_items.dataProvider.addItem({barcode_number:" ", time:new Date(), weight:" "}); dg_items.focusedCell = {columnIndex:0, itemIndex:dg_items.dataProvider.length - 1}; What I think is happening based ...

  1. #1

    Default Cell Focus after adding a new DataGrid item

    I am trying to add a new item to a datagrid instance and then set focus to the
    first cell of the new record.

    There appears to be a sequencing error that is keeping the cell from retaining
    focus in doing this. What is very strange is that the cell focus works if
    there are enough items in the grid to have a vertical scroll bar visible, but
    it will not otherwise. Below is the code I am using in this process:

    dg_items.dataProvider.addItem({barcode_number:" ", time:new Date(), weight:"
    "});
    dg_items.focusedCell = {columnIndex:0, itemIndex:dg_items.dataProvider.length
    - 1};

    What I think is happening based on tracing out several events and observation
    of the UI is that the focusedCell property is being set before the item being
    added has rendered in the grid (drawn). I even tried placing the focusedCell
    set in a doLater and that did not help (although creating an interval at 200 ms
    seemed to work, but I consider this quite a cludge). Why this is not a problem
    when a scroll bar is present I really cannot say.

    Does anyone know of an event that will fire when a new item has successfully
    rendered in a grid? Tried childCreated and that did not seem to do the trick
    either.

    Thanks,
    Anthony McClure

    Flex Architect Guest

  2. #2

    Default Re: Cell Focus after adding a new DataGrid item

    The doLater() has always worked for me in this situation.

    Can you reproduce this behavior in a sample app?

    Tracy
    ntsiii Guest

  3. #3

    Default Re: Cell Focus after adding a new DataGrid item

    Very strange...

    I did what you suggested Tracy and created just a simple app with only the
    grid a button to add the item and the requisite code. It works. Only inside
    of the much more complex dashboard application does doLater() seem to fire
    before the item is loaded. I am kind of stumped here.

    Flex Architect Guest

  4. #4

    Default Re: Cell Focus after adding a new DataGrid item

    Your real app is probably to complex to use this technique, but when I have a
    situation where an example works but my code does not, I take the working code
    and add my stuff to it until it breaks.

    If that is not practical, maybe you should try TWO doLaters(). doLaters occur
    in the very next frame, and so are probably "better" than setInterval.

    Tracy

    ntsiii Guest

  5. #5

    Default Re: Cell Focus after adding a new DataGrid item

    Ultimately I ended up using two doLaters. Would be nice if there was a way to specify the amount of delay as an argument.

    Thanks again!
    Flex Architect Guest

Similar Threads

  1. How do I set the focus of a datagrid cell
    By eclesia in forum Macromedia Flash Data Integration
    Replies: 0
    Last Post: January 13th, 05:34 PM
  2. Setting focus to first editable cell in datagrid
    By greenb in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: July 11th, 07:46 PM
  3. Set focus to datagrid cell
    By PontiMax in forum ASP.NET Data Grid Control
    Replies: 2
    Last Post: March 2nd, 02:56 PM
  4. Replies: 1
    Last Post: September 22nd, 04:12 PM
  5. Adding listbox in DataGrid item
    By Lohadas in forum ASP.NET Building Controls
    Replies: 0
    Last Post: September 18th, 10:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139