Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
25
How do you manually bind to ObservableCollection of ObservableCollection ?
posted

I mean i need to bind unbound fields programmatically but i cannot manage to bind to a DataSource of type ObservableCollection<ObservableCollection<String>> sCol :

        <igDP:XamDataGrid x:Name="xamDataGrid" DataSource="{Binding sCol}">
            <igDP:XamDataGrid.FieldLayoutSettings>
                <igDP:FieldLayoutSettings AutoGenerateFields="False" />
            </igDP:XamDataGrid.FieldLayoutSettings>
            <igDP:XamDataGrid.FieldLayouts>
                <igDP:FieldLayout>
                    <igDP:FieldLayout.Fields>
                        <igDP:UnboundField Label="Col1" BindingPath="[0]" BindingMode="TwoWay" DataType="sys:String" />
                        <igDP:UnboundField Label="Col2" BindingPath="[1]" BindingMode="TwoWay" DataType="sys:String"/>
                    </igDP:FieldLayout.Fields>
                </igDP:FieldLayout>
            </igDP:XamDataGrid.FieldLayouts>
        </igDP:XamDataGrid>

Ouput traces say :

System.Windows.Data Error: 39 : BindingExpression path error: '[' property not found on 'object' ''EnumerableObjectWrapper' (HashCode=14407208)'. BindingExpression:Path=[1]; DataItem='EnumerableObjectWrapper' (HashCode=14407208); target element is 'a' (HashCode=44344604); target property is 'Value' (type 'Object')

I can achive a correct binding through a regular listView though :

        <ListView ItemsSource="{Binding sCol}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Col1" DisplayMemberBinding="{Binding [0]}"/>
                    <GridViewColumn Header="Col2" DisplayMemberBinding="{Binding [1]}"/>
                </GridView>
            </ListView.View>
        </ListView>

It seems that the grid DataSource property does not behave like the list ItemsSource property.

What am I missing ?

Cheers.

  • 25
    posted

    Just to let you know that I also managed to make the Xceed grid works in the same context :

             <xcdg:DataGridControl Name="xtraGrid"
                                  ItemsSource="{Binding Source={StaticResource xtraGridView}}"
                                  AutoCreateColumns="False" >
                <xcdg:DataGridControl.Columns>
                    <xcdg:Column FieldName="[0]" Title="Col1" />
                    <xcdg:Column FieldName="[1]" Title="Col2" />
                </xcdg:DataGridControl.Columns>
            </xcdg:DataGridControl>

    We are actually trying various WPF datagrids on the market to make our choice for my job. I would be very disappointed if we could not go further with your grid. I m sure it's just my mistake and not an issue with your design.

    Please help :-)

    • 1336
      posted in reply to philippe

      Hi,

      Has anyone found a solution to this problem? 

       We are experiencing exactly the same thing. In C# only an indexer can take a parameter so you have to be able to specify a parameter without a property as this post describes, i.e. FieldName="[0]".

       Cheers,

      Dave

      • 69686
        posted in reply to Dave Dansey

         Hello,

        I  would like to propose a workaround for this. It is working fine if you replace the ObservableCollection<ObservableCollection<String>> with ObservableCollection<WorkaroundClass> where the WorkaroundClass has a public property of type ObservableCollection :

        public class WorkAround
                {
                    public ObservableCollection<String> obs { get; set; }
                    public WorkAround()
                    {
                        obs = new ObservableCollection<string>();
                        obs.Add("string1");
                        obs.Add("string2");
                        obs.Add("string3");
                    }
                }

        Hope this helps.