views:

832

answers:

1

i have an HGroup that contains a DataGroup with an ArrayCollection for a dataProvider.

the DataGroup has a VScrollBar attached to it.

how can i make sure that whenever new rows are added to the ArrayCollection, the dataGroup will scroll down ?

this window is gonna be used for a chat application so whenever new rows are added i need to see the new rows.

i know that i can perform the following command to scroll down: chatScrollBar.value=chatScrollbar.maximum

but what event do i need to attach to in order to run this command whenever a new row is visible ?

<s:HGroup width="100%">
 <s:DataGroup id="vertView"  
     clipAndEnableScrolling="true" width="100%" height="60"
     dataProvider="{chatMessages}">

  <s:itemRenderer>
   <fx:Component>
    <s:ItemRenderer width="100%" height="8">
     <s:states>
      <s:State name="normal" />
      <s:State name="hovered" />
     </s:states>

     <s:RichText  text="{ data }" textAlign="left" paddingLeft="2" color="black" color.hovered="blue"/>
    </s:ItemRenderer>
   </fx:Component>
  </s:itemRenderer>

  <s:layout> 
   <s:VerticalLayout useVirtualLayout="true"/> 
  </s:layout> 
 </s:DataGroup> 
 <s:VScrollBar id="chatScrollBar" viewport="{vertView}" 
      height="{vertView.height}" />

</s:HGroup>
+1  A: 

You have to set the verticalScrollPosition. See here or here. Or try this for a Spark List:

<s:List id="list"
            horizontalCenter="0"
            verticalCenter="0">
        <s:layout>
            <s:VerticalLayout id="vLayout" requestedRowCount="4"
                    verticalScrollPosition="{vLayout.maxScrollPosition}" />
        </s:layout>
</s:list>
Thomas
unfortunately valueCommit does not get executed whenever i add a row,i tried using s:List instead of s:DataGroup but i got the same results
ufk
Try the example I added.
Thomas
VerticalLayout does not have maxScrollPosition
ufk
Ah you're right. Only have FB4 at work. And when you try chatScrollBar.maxScrollPosition? Will try it myself at work tomorrow.
Thomas
currently i don't have chatScrollBar because i moved to a List. i would prefer if we would find a solution with List. thanks for all of your assistance
ufk
I will look for it tomorrow :-)
Thomas