---
title: "how can i access the textbox inside the datagrid using the events of that datagrid?"  
description: "how can i access the textbox inside the datagrid using the events of that datagrid?"  
author: "Jayden Bell"  
published: 2013-09-03  
updated: 2013-09-03  
canonical: https://www.mindstick.com/forum/1431/how-can-i-access-the-textbox-inside-the-datagrid-using-the-events-of-that-datagrid  
category: "wpf"  
tags: ["wpf"]  
reading_time: 1 minute  

---

# how can i access the textbox inside the datagrid using the events of that datagrid?

I have a [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) in a datagrid that is designed using xaml. Can I [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) the textbox which has been designed in xaml previously in codefile using the [events](https://www.mindstick.com/blog/102/events-in-c-sharp) of the datagrid. Please help me.....................

```
      <Window x:Class="GridTextBox.Test"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" WindowState="Maximized"    Title="Test" Height="300" Width="300" Loaded="Window_Loaded"><Grid>    <Grid.RowDefinitions>        <RowDefinition Height="30"/>        <RowDefinition Height="*"/>        <RowDefinition Height="30"/>    </Grid.RowDefinitions>    <Grid.ColumnDefinitions>        <ColumnDefinition Width=".25*"/>        <ColumnDefinition Width=".25*"/>        <ColumnDefinition Width=".25*"/>        <ColumnDefinition Width=".25*"/>    </Grid.ColumnDefinitions>    <DataGrid Grid.Row="1" Grid.Column="1"  Name="datagrid1" SelectionChanged="datagrid1_SelectionChanged" LoadingRowDetails="DataGrid_LoadingRowDetails"  Height="auto" Width="auto">        <DataGrid.Columns>            <DataGridTemplateColumn>                <DataGridTemplateColumn.CellTemplate>                    <DataTemplate>                        <TextBox Name="txtEmpid" Text="hiiiiii"></TextBox>                    </DataTemplate>                </DataGridTemplateColumn.CellTemplate>            </DataGridTemplateColumn>        </DataGrid.Columns>    </DataGrid></Grid>
```

## Replies

### Reply by Sumit Kesarwani

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.

ContainerFromItem(datagrid1.SelectedItem);

then get the TextBlock like this:

var text = datagrid1.Columns[0].GetCellContent(row) as TextBlock;


---

Original Source: https://www.mindstick.com/forum/1431/how-can-i-access-the-textbox-inside-the-datagrid-using-the-events-of-that-datagrid

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
