Mohit
Mohit

Reputation: 1

how can I access a datagrid (sub grid) control that is inside another DataGrid.RowDetailsTemplate

<DataGrid x:Name="maingrid" Grid.Row="0" ItemsSource="{Binding view}" HorizontalScrollBarVisibility="Auto" AlternationCount="2" HorizontalAlignment="Stretch" AutoGenerateColumns="False" CanUserAddRows="False"RowDetailsVisibilityMode="Visible">

        <DataGrid.Columns>
            <DataGridTextColumn  Header="Name" Binding ="{Binding Name}" IsReadOnly="True"  />
            <DataGridTextColumn  Header="ChangeOwn" Binding ="{Binding Own,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
            <DataGridTextColumn  Header="Approval" Binding ="{Binding ChangeApproval,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
        </DataGrid.Columns>
        <DataGrid.RowDetailsTemplate>
            <DataTemplate>
                <DataGrid Margin="80,8,8,8" 
                         x:Name="subgrid" Grid.Row="1"
                          IsSynchronizedWithCurrentItem="True"
                       ItemsSource="{Binding subcat, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}"
                       SelectedItem="{Binding Path=DataContext.SelectCategory, 
                                        RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}},
                                        Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=True}" >
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="SubCategoryName" IsReadOnly="True" Binding="{Binding Path = SubCategoryName,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=True}"/>
                        <DataGridTextColumn Header="DocumentNumber" Binding="{Binding DocumentNumber,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=True}"/>
                       <DataGridTextColumn Header="InHours" Binding="{Binding ChangeImpactInHours,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged,NotifyOnSourceUpdated=True}"/>
                        </DataGrid.Columns>
                </DataGrid>
            </DataTemplate>
        </DataGrid.RowDetailsTemplate>
        <DataGrid.GroupStyle>
            <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
                <GroupStyle.Panel>
                    <ItemsPanelTemplate>
                        <DataGridRowsPresenter/>
                    </ItemsPanelTemplate>
                </GroupStyle.Panel>
            </GroupStyle>
        </DataGrid.GroupStyle>
    </DataGrid>

I want code behind (C#) to access the subgrid controls and subgrid column width that I want to change according to size of window .

Upvotes: 0

Views: 187

Answers (1)

Somar Zein
Somar Zein

Reputation: 170

Normally you should not have to manage size in code behind (unless you have to) , but here are some links which maybe could be useful to you case:

Upvotes: 0

Related Questions