1
Answer

How to reference indevedual controls in wpf DataGrid Visual Studio 2010

zerak

zerak

14y
4.7k
1
I am using Visual Studio 2010 beta 2. I created a WPF application that has a DataGrid. I am able to bind the DataGrid to a DataTable. The DataGrid has one column that is a DataGridTemplateColumn contains a TextBox control.

<DataGrid.Columns>
                <DataGridTemplateColumn ClipboardContentBinding="{x:Null}" Header="Notes" CanUserReorder="False" CanUserResize="True" CanUserSort="True" Width="210">                   
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding  Notes}"  Padding="5,5,5,5" Width="200" Height="100" AcceptsReturn="True" AcceptsTab="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible"></TextBox>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

I have a "Save" button that once it is clicked, I need to get what the user typed in the TextBox. Is there a way I can loop through the DataGrid and access each Row, Cell control? For example, TextBox tx = (TextBox)DataGrid1.Rows[0][0].

Your help will be greatly appreciated

Answers (1)