Datagrid refreshing after HTTPService update

Hey guys,

For my school project I developed Flex app. There is datagrid component, binded to a data provider as <mx:DataGrid id="dgTextContent" x="9" y="4" width="651" height="176" dataProvider="{getRecord.lastResult.rss.channel}">
I use an HTTPService as follow: <mx:HTTPService id="postRecord" url="postRecord.php" method="POST" contentType="application/x-www-form-urlencoded" resultFormat="text" result="addRecordMsg(event)">
<mx:request>
<number>{number.text}</number>
<content>{content.text}</content>
</mx:request>
</mx:HTTPService>
I have a button <mx:Button id="addRecordBtn" x="156" y="463" label="add" click="postRecord.send(), getRecord.send()"/> for adding new record in the data base via postRecord.php script. So,in fact, it works(i checked via phpMyadmin records in the table) , but there is a small annoying problem with displaing new data on the datagrid visual control. The new added data are not displayed after inserting. When i switch between the states in my app and come back to the current state - the magic appears - data are displayed! Here is my question: How could i avoid this situation to switch between states or hitting update button few times to refresh newly added data?
Thanks in advance

Looks like all you need to do is refresh your dataprovider? Could it be that simple?

Thanks for ur suggestionq also i’ve readed the article you mentioned. The point is that i’m not using ArrayCollection in my Dataprovider. I gues that you suggest me to use this approach:
var datapro:ArrayCollection = new ArrayCollection();

function dataRefresh():void
{
datapro.refresh();
}
<mx:DataGrid id=“datagrid1” creationComplete=“datagrid1_creationCompleteHandler(event)” dataProvider="{datapro}">

But where is HTTPService call then?

Sorry if i sound like dilettante - in fact AS3 is not my power.
Lets assume that
var datapro:ArrayCollection = new ArrayCollection()
and we can define datapro refresh fucntion.
ok here is my code with Your data provide suggestion:
<mx:DataGrid id="dgTextContent" dataProvider="{datapro}" >
I don’t get it how to bind this with my HTTPService call
<mx:HTTPService id="getRecord" url="getRecord.php" useProxy="false" />

Thanks

Hey Linusj,

Yeah , I solve the case.
As far as I know the HTTPService is an asynchronous call which mean that separate calls could take different times to complete.
The using the result even handler gives time to the main HTTPService - postRecord - posting the New Record in the Data Base. And after “while” in the Result Even Handler (addRecordMsg(event)) my second HTTPService calls getRecord (gets all records in Data base, including new ones) does the refreshing the Data Grid.
This safe me a lot of time. And have to confess - At first i’m an animator and graphic designer. Coding steps after.

Thanks
Olav