Select to view content in your preferred language

bind to a nested data grid

1336
2
01-30-2012 10:28 AM
ChrisBradberry
Deactivated User
Hey,

I have a datagrid that has a data source from an identity task.  Within the datagrid, I have a row details template with another data grid nested there.  The nested data grid data source is from a query task to a service.  The problem is that I cannot seem to bind to the nested datagrid in the code behind, and when I try to bind to it in the xaml, nothing happens.

Here is the xaml, and the _FSUnit is defined in the code behind as a public FeatureSet

<sdk:DataGrid x:Name="UnitDataGrid" AutoGenerateColumns="False" Background="White" ItemsSource="{Binding _FSUnit.features}"
                                      IsReadOnly="True"  HorizontalAlignment="Center" VerticalAlignment="Bottom" HeadersVisibility="Column"
                                     ColumnWidth="SizeToCells" HorizontalContentAlignment="Stretch" >


In the ExecuteCompleted method, I put
_FSUnit = e.FeatureSet;


I have tried a few combinations of things and the data is correct in the first datagrid, but when I click on the row, none of the binding seems to work.  When I step through the code, I can see the correct data within the featureSet, but can't retrieve it.

Any ideas?

Thanks, Chris
0 Kudos
2 Replies
DominiqueBroux
Esri Frequent Contributor
ItemsSource="{Binding _FSUnit.features}"

With this code the datacontext of your datagrid rows is a graphic (not a dictionary of attributes).
That's not a problem but you have to take care of that when defining the rows of your datagrid and include 'Attribute' in your binding.
Example with the interactive SDK:

                 <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn CanUserSort="True" Binding="{Binding Attributes[STATE_NAME]}" Header="State Name"/>
                        <sdk:DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[SUB_REGION]}" Header="Region"/>
                        <sdk:DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[STATE_FIPS]}" Header="FIPS"/>
                        <sdk:DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[STATE_ABBR]}" Header="Abbreviation"/>
                        <sdk:DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[POP2000]}" Header="Population 2000"/>
                        <sdk:DataGridTextColumn CanUserSort="True"  Binding="{Binding Attributes[POP2007]}" Header="Population 2007"/>
                    </sdk:DataGrid.Columns>
0 Kudos
ChrisBradberry
Deactivated User
Dominique,

The real issue was with the nested datagrid.  I was not able to set the item source in the code behind.  So I moved it out of the row definition and then I could get to it to set the items source. 

Thanks, Chris
0 Kudos