c# - 在数据网格中查找文本框

标签 c# wpf

我有一个包含四列的数据网格。

因此,从 C# 端的数据网格中,我想找到名称为“headBox”的特定文本框

我该怎么做?我的专栏 xaml 如下所示。此部分位于 Datagrid.Columns 内,它位于 name = dgrid 的 datagrid 标记内

<DataGridTemplateColumn Header="Header">
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                  <TextBox Name="HeadBox"/>
        </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

最佳答案

我觉得你可以用

DataGridRow row = myDataGrid.ItemContainerGenerator.ContainerFromIndex
(myDataGrid.SelectedIndex) as DataGridRow;

var i = 0; /// Specify your column index here.

编辑

TextBox ele = ((ContentPresenter)(myDataGrid.Columns[i].GetCellContent(row))).Content as TextBox;

关于c# - 在数据网格中查找文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7962092/

相关文章:

c# - NUnit Console Runner 可以即时报告失败的测试吗?

c# - 带有图标和文本的 WPF TreeView

c# - 在构建时数据类型未知时将数据对象映射到合适的 ViewModel

c# - WPF - 为基类实现 System.ComponentModel.INotifyPropertyChanged

c# - 如何更改 WPF 进度条上的颜色

c# - 如何让 MahApps CleanWindow 工作?

c# - 找到属于 InvocationExpressionSyntax 的 UsingDirectiveSyntax

c# - 不应使用哪些键盘快捷键?

c# - Xamarin.Forms 2.2 的签名板

c# - 哪个更好?数组、ArrayList 或 List<T>(在性能和速度方面)