Welcome to the Xceed Community | Help
Community Search  

Dynamic Binding of an Enumerable Collection

Sort Posts: Previous Next
  •  04-22-2008, 7:49 AM Post no. 11644

    Dynamic Binding of an Enumerable Collection

    Hi everyone,

    I have set the ItemSource property to an Enumerable Collection (which is changing dynamically by our Entity-Framework).
    I have created the columns manually (because I want to show only a subset of the data).
    At first, the data is displayed according to the enumerable. When I change something via the DataGrid, it doesn't update the enumerable member. Only when I sort (or move) the columns, the enumerable gets its update.
    The same happens in the opposite direction - if the collection changes, it only updates the DataGrid when re-sorting or moving the columns seperator.

    I would like to have dynamic-binding, i.e. update the collection whenever our user changes something through the DataGrid, and update the DataGrid whenever our collection changes.

    XAML:

    <Xceed:DataGridControl x:name="DataGrid1" AutoCreateColumns="False"/>

    C#:

    (note: enumrable1 = IEnumrable from entity framework, columnsDetails = names of columns that should be used)

    DataGrid1.ItemsSource = enumrable1;

     foreach (var x in columnsDetails) { DataGrid1.Columns.Add(new Column(x.PropertyName, x.Header, null);}

    Thanks!
    Assaf

  •  04-22-2008, 10:10 AM Post no. 11645 in reply to 11644

    Re: Dynamic Binding of an Enumerable Collection

    Hi,

      For the DataGridControl to receive change notifications from the Data Source, the Data Source needs to implement either IBindingList or INotifyCollectionChanged. I also recommend encapsulating the Data Source within a DataGridCollectionView to benefit from several optimizations made ( grouping, sorting, insertion, ... ).

      For the DataGridControl to receive change notifications from the elements within the Data Source, the elements need to implement INotifyPropertyChanged or use DependencyProperties (through base class DependencyObject).

    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.