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 :

<DataGrid ColumnWidth="*" Name="dgUsers" Grid.ColumnSpan="5" Grid.Row="4" Margin="10,0,10,4"
                                  AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False"
                                  SelectionMode="Single" SelectionUnit="FullRow" HeadersVisibility="Column">
                                <DataGridTextColumn x:Name="Name" Header="Name"  Binding="{Binding Path=Name}"/>
                                <DataGridTextColumn x:Name="Family" Header="Family"  Binding="{Binding Path=Family}"/>
                                    <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">


i want access to txtName in event BtnDeleteClick.
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:
Message=Operation Is valid only for elements using that template.
at System.Windows.FrameworkTemplate.FindName(String name, FrameworkElement templatedParent)
at ProductionOverviewModule.View.ProductionOrdersGrid.GetRowDetailTemplateGrids() in fileName.cs:line 86

for more about see link[^]
Share this answer
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