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.

Parents
  • 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 :-)

Reply Children