Home > DeveloperSection > Forums > how can i access the textbox inside the datagrid using the events of that datagrid?
Jayden Bell
Jayden Bell

Total Post:105

Posted on    September-03-2013 8:20 AM


 1 Reply(s)
 1921  View(s)
Rate this:

I have a textbox in a datagrid that is designed using xaml. Can I access the textbox which has been designed in xaml previously in codefile using the events of the datagrid. Please help me.....................

      <Window x:Class="GridTextBox.Test"


    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowState="Maximized"

    Title="Test" Height="300" Width="300" Loaded="Window_Loaded">



        <RowDefinition Height="30"/>

        <RowDefinition Height="*"/>

        <RowDefinition Height="30"/>



        <ColumnDefinition Width=".25*"/>

        <ColumnDefinition Width=".25*"/>

        <ColumnDefinition Width=".25*"/>

        <ColumnDefinition Width=".25*"/>


    <DataGrid Grid.Row="1" Grid.Column="1"  Name="datagrid1" SelectionChanged="datagrid1_SelectionChanged" LoadingRowDetails="DataGrid_LoadingRowDetails"  Height="auto" Width="auto">





                        <TextBox Name="txtEmpid" Text="hiiiiii"></TextBox>







Sumit Kesarwani

Total Post:378

Posted on    September-03-2013 8:25 AM

Hi Jayden,

Firstly, you need to get use ItemContainerGenerator to get the correct row from data (in your datagrid1_SelectionChanged event).

var row = (DataGridRow)datagrid1.ItemContainerGenerator.


then get the TextBlock like this:

var text = datagrid1.Columns[0].GetCellContent(row) as TextBlock;

Don't want to miss updates? Please click the below button!

Follow MindStick