If you have:

var myList : ArrayCollection = new ArrayCollection();

And it's not bindable, but points to objects that are, then a component that
has it as a dataProvider will update when you add an item, or remove an
item, or change an item. But, since the "myList" variable itself is not
bindable, you could do this:

myList = new ArrayCollection();

And there'd be no update, and myDatagrid.dataProvider would still point to
the old ArrayCollection.

-J

On Mon, May 19, 2008 at 7:02 PM, gaurav1146 <[EMAIL PROTECTED]> wrote:

>   Hi,
> Thanks, I now get that addItem method was responsible for triggering
> the property change event. But I am not very clear what purpose does
> it serve to have the dataProvider as Bindable. Based on your example I
> created a class Company and used an Arraycollection companyList to
> display companies in the datagrid. It did not matter whether the
> companyList was Bindable or not. All that was required was that the
> name property of Company should be Bindable. Also for a list
> containing Object the value of the datagrid was not updated if any
> object property was changed irrespective of whether the list is
> Bindable or not.
> The thing is that if I do not set the dataprovider as Bindable
> I get a warning that Data Binding would not be able to detect
> assignments to the dataProvider. I would be grateful if you could
> point me to a scenario where declaring the dataProvider as Bindable
> makes a difference. Would it be in cases like where I use something
> like dataGrid2.dataProvider = {dataGrid1.dataProvider}.
>
> Following is the modified code that I tried out:
>
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="absolute" initialize="createCompanies()">
> <mx:Script>
> <![CDATA[
> import mx.collections.ArrayCollection;
> [Bindable]
> public var dp:ArrayCollection = new
> ArrayCollection([{index:1,word:"Test1"},{index:2, word:"Test2"}]);
> public var companyList:ArrayCollection = new ArrayCollection();
>
> /*
> * Does not work as the word property in Object is not bindable
> */
> public function changeDataProvider():void
> {
> var obj:Object = dp.getItemAt(0);
> obj["word"] = "Modified Test";
> }
>
> public function createCompanies():void{
> var c1:Company = new Company();
> var c2:Company = new Company();
> c1.name= "ABC";
> c2.name = "XYZ";
> companyList.addItem(c1);
> companyList.addItem(c2);
> }
>
> /*
> * Works if name is declared as Bindable in the Company class
> */
> public function changeCompany():void{
> var obj:Company = companyList.getItemAt(0) as Company;
> obj.name = "ABC Modified";
> }
> ]]>
> </mx:Script>
> <mx:HBox>
> <mx:VBox>
> <mx:DataGrid dataProvider="{dp}"/>
> <mx:Button click="changeDataProvider()" label="Change data"/>
> </mx:VBox>
> <mx:VBox>
> <mx:DataGrid dataProvider="{companyList}">
> <mx:columns>
> <mx:DataGridColumn dataField="name" headerText="Company"/>
> </mx:columns>
> </mx:DataGrid>
> <mx:Button click="changeCompany()" label="Change Company"/>
> </mx:VBox>
> </mx:HBox>
> </mx:Application>
>
> *******Company.as****************
> package
> {
> public class Company
> {
> public function Company()
> {
> super();
> }
> [Bindable]
> public var name:String;
>
> }
> }
>
> --- In flexcoders@yahoogroups.com <flexcoders%40yahoogroups.com>, "Josh
> McDonald" <[EMAIL PROTECTED]> wrote:
> >
> > If you call addItem(), updateItem(), etc, the PropertyChangedEvent is
> > dispatched by the IList implementor (ie, ArrayCollection).
> >
> > But, if you have an IList of objects, and you do this:
> >
> > var company : Company = companyList.getItemAt(3) as Company;
> > company.name = "New name";
> >
> > then you'll only get the new data on screen if Company (or
> Company.name) is
> > marked [Bindable]
> >
> > When you call the modifying methods on the dataprovider itself, then the
> > change is marked as happening on the IList (and it dispatches the
> > PropertyChangedEvent). But if you change the content of an object
> contained
> > within that list, nobody knows about it unless you add the [Bindable].
> > [Bindable] is a compile-time decorator that dispatches the events on
> your
> > behalf.
> >
> > If I'm making things muddier rather than clearer with that, let me
> know ;-)
> >
> > -J
> >
> > On Mon, May 19, 2008 at 2:01 PM, gaurav1146 <[EMAIL PROTECTED]> wrote:
> >
> > > Hi,
> > > I have been using Bindable tag for data providers in datagrid, list
> > > etc. The doc states that this ensures that the destination datagrid
> > > would reflect the change when the dataprovider is changed. But I have
> > > observed that even if I do not use the Bindable tag the datagrid is
> > > still updated when the dataprovider changes. Here is a simple example:
> > >
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> > > layout="absolute">
> > > <mx:Script>
> > > <![CDATA[
> > > import mx.collections.ArrayCollection;
> > > /*Bindable tag not added. Flex Builder gives a warning when
> > > the variable is referenced in the datagrid but it still works.*/
> > > private var dp:ArrayCollection = new ArrayCollection([{index:1,
> > > word:"Test1"},{index:2, word:"Test2"}])
> > > public function changeDataProvider():void
> > > {
> > > var obj1:Object = new Object();
> > > obj1["index"] = 1;
> > > obj1["word"] = "Modified Test1";
> > > dp.setItemAt(obj1,0);
> > > var obj2:Object = new Object();
> > > obj2["index"] = 3;
> > > obj2["word"] = "Test3";
> > > dp.addItem(obj2);
> > > }
> > > ]]>
> > > </mx:Script>
> > > <mx:VBox>
> > > <mx:DataGrid dataProvider="{dp}"/>
> > > <mx:Button click="changeDataProvider()" label="Change data"/>
> > > </mx:VBox>
> > > </mx:Application>
> > >
> > > In the above example the datagrid changes on the button click. Please
> > > let me know if I am missing somthing.
> > >
> > >
> > >
> >
> >
> >
> > --
> > "Therefore, send not to know For whom the bell tolls. It tolls for
> thee."
> >
> > :: Josh 'G-Funk' McDonald
> > :: 0437 221 380 :: [EMAIL PROTECTED]
> >
>
>  
>



-- 
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]

Reply via email to