Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to access txtName in DataGrid.RowDetailsTemplate in runtime :

my code :

C#
<DataGrid ColumnWidth="*" Name="dgUsers" Grid.ColumnSpan="5" Grid.Row="4" Margin="10,0,10,4"
                                  AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
                                  IsReadOnly="True"
                                  SelectionMode="Single" SelectionUnit="FullRow" HeadersVisibility="Column">
                            <DataGrid.Columns>
                                <DataGridTextColumn x:Name="Name" Header="Name"  Binding="{Binding Path=Name}"/>
                                <DataGridTextColumn x:Name="Family" Header="Family"  Binding="{Binding Path=Family}"/>
                            </DataGrid.Columns>
                            <DataGrid.RowDetailsTemplate>
                                <DataTemplate>
                                    <Grid Margin="0,10,0,10" >
                                        <TextBox Name="txtName" Margin="0,2,0,2" Text="{Binding Path=Name}" />
                                        <TextBox Name="txtFamily" Margin="0,2,0,2" Text="{Binding Path=Family}" />
                                        <TextBox Name="txtUserName" Margin="0,2,0,2" Text="{Binding Path=UserName}"  />
                                            <Button Background="#FF7F9D0E" Height="60" Name="btnDelete" TabIndex="8" Width="60" Margin="30,0,30,0" Click="BtnDeleteClick">
                                    </Grid>

                                </DataTemplate>
                            </DataGrid.RowDetailsTemplate>
                        </DataGrid>



i want access to txtName in event BtnDeleteClick.
Posted
Comments
Thomas Duwe 8-Apr-13 2:57am    
Do you want access to the TextBox or the bound value of the TextBox?

1 solution

The desired RowDetailsTemplate content is available just then the row is expanded.
Till this event (see LoadingRowDetails) the content is null and Try to find it with DataGridDetailsPresenter.ContentTemplate leads to an exception:
System.InvalidOperationException
HResult=0x80131509
Message=Operation Is valid only for elements using that template.
Source=PresentationFramework
StackTrace:
at System.Windows.FrameworkTemplate.FindName(String name, FrameworkElement templatedParent)
at ProductionOverviewModule.View.ProductionOrdersGrid.GetRowDetailTemplateGrids() in fileName.cs:line 86

for more about see link https://stackoverflow.com/questions/5679648/why-would-this-contenttemplate-findname-throw-an-invalidoperationexception-on[^]
 
Share this answer
 
Comments
Graeme_Grant 21-Feb-24 3:53am    
Please do not answer 10+ year old questions. Focus on current questions instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900