1

I've created a Datagrid in a Datagrid.RowDetailsTemplate and I would like use Items.refresh on it when I click on a button created outside of my Datagrid.

I can't find a way to access this function for datagrid_Detail with the button button_refreshDetail. Here is my code :

<DataGrid x:Name="datagrid" HorizontalAlignment="Left" Height="618" Margin="10,74,0,0" VerticalAlignment="Top" Width="1472" AutoGenerateColumns="False" LoadingRowDetails="datagrid_LoadingRowDetails" CanUserAddRows="False">
    <DataGrid.Columns>
        <DataGridTextColumn Header="a" Binding="{Binding a}" Width="*"/>
        </DataGrid.Columns>
        <DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <DataGrid x:Name="datagrid_Detail" ItemsSource="{Binding b}" AutoGenerateColumns="False" SelectionChanged="datagrid_Detail_SelectionChanged" MouseLeftButtonUp="datagrid_Detail_MouseLeftButtonUp">
                    <DataGrid.Columns>
                        <DataGridCheckBoxColumn Header="c" Binding="{Binding c, Mode=TwoWay}" IsReadOnly="False"/>
                        <DataGridTextColumn Header="d" Binding="{Binding d, Mode=TwoWay}" IsReadOnly="False"/>
                        <DataGridComboBoxColumn Header="e" x:Name="combobox_e"/>
                        <DataGridComboBoxColumn Header="f" x:Name="combobox_f"/>
                        <DataGridTextColumn Header="g" Binding="{Binding g, Mode=TwoWay}" IsReadOnly="False"/>
                        <DataGridComboBoxColumn Header="h" x:Name="combobox_h"/>
                        <DataGridComboBoxColumn Header="i" x:Name="combobox_i"/>
                        <DataGridTemplateColumn Width="45" Header="j">
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Image Source="j.png" Width="20" Height="20"/>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>
                    </DataGrid.Columns>
                </DataGrid>
            </DataTemplate>
        </DataGrid.RowDetailsTemplate>
    </DataGrid>
    <Button x:Name="button_refreshDetail" Content="button_refreshDetail" HorizontalAlignment="Left" Height="26" Margin="129,697,0,0" VerticalAlignment="Top" Width="118" Click="button_refreshDetail"/>

Thank you for your help.

SlaneR
  • 684
  • 5
  • 19
Artcha
  • 11
  • 2

2 Answers2

0

Couldn't you just use that collection named "b" in order to alter the items?

If the binding is well configured and by that i mean :

  • b is an ObservableCollection

and every custom data type in your collection

  • implements INotifyPropertyChanged

you should be able to update the properties of each object or add/remove items from the collection and the view will be updated with no other extra code.

At least this is something I would do. Maybe i am not understanding very well your refreshing scenario.

Olaru Mircea
  • 2,570
  • 26
  • 49
  • My scenario is : - I sort a column of my datagrid_Detail - I update my data - My data are updated but the datagrid dispay isn't because of the sorting.. – Artcha Jul 13 '15 at 14:09
0

Use ICollectionView and SortDescription to sort DataGrid. It may not be a good idea to access datagrid_Detail, but manipulate the underlying data instead.

dytori
  • 487
  • 4
  • 12