--- In [email protected], "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}.
The reason you get the warning when it is not bindable is you're
using the {} notation. That is specifically telling Flex to use a
bindable variable. If that variable weren't set prior to your
component's being drawn by the Framework, you would actually have an
empty datagrid--simply assigning a value to the dataProvider variable
would not populate the grid. One advantage of using a bindable
variable is that you don't have to worry about setting your
dataprovider explicitly at the right time to allow the Framework to
lay out and size your component correctly.
For instance, if your component that needs a dataProvider is a child
of a List component, then the first time the component is drawn, the
dataChange event will happen before that child exists. If you try to
set the dataProvider in code yourself, you might be tempted to try to
use the dataChange event to do that setting. But this won't work
because the child component hasn't been drawn.
So if you _don't_ use data binding, you need to really understand the
component lifecycle, since you'll need to assign the dataprovider to
the component yourself at the correct time, in an override of the
commitProperties() method. When you _do_ use dataBinding, simply
assigning a value (or a new value) to the variable triggers the
Framework to handle all of this for you.
What you're seeing with the ArrayCollection type is something
slightly different from data binding. In essence, this variable type
is specifically designed to talk to your dataGrid and stay in synch.
When you change something inside an ArrayCollection element, you can
get your dataProvider to update by calling the refresh() method on
the ArrayCollection. I think this works whether the ArrayCollection
itself is bindable or not. I'm a bit fuzzy on the details of that,
so I'll leave it to more experienced developers to flesh that out if
you need more info.
HTH;
Amy