WPF 取 DataGrid TextBox所在行数据

前台:

 <DataGrid Name="gridWuLiaoZhuiSu" AutoGenerateColumns="False" CanUserAddRows="False" Grid.Row="1" Style="{StaticResource DataGrid_WuLiaoZhuiSu}" ColumnHeaderStyle="{StaticResource DataGrid_WuLiaoZhuiSu_Header}" RowStyle="{StaticResource DataGrid_WuLiaoZhuiSu_Row}" CellStyle="{StaticResource DataGrid_WuLiaoZhuiSu_Cell}" >
                        <DataGrid.Columns>

                            <DataGridTextColumn Header="物料编码" Width="150*" Binding="{ Binding Path=MATERIAL_CODE }" IsReadOnly="True"></DataGridTextColumn>
                            <DataGridTemplateColumn Header="扫描内容" Width="200*">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBox x:Name="appealstate2"  TextWrapping="Wrap" Text="{Binding Path=DATA_CODE,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  Background="White" Foreground="Black" Width="200" Height="30" VerticalContentAlignment="Center"   KeyDown="Appealstate2_KeyDown" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                  
                        </DataGrid.Columns>
                    </DataGrid>

后台:

 private void Appealstate2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key.Equals(Key.Enter))
            {
                Model.base_step_material model=(sender as TextBox).DataContext as Model.base_step_material;
                var d2 = this.gridWuLiaoZhuiSu.ItemsSource;
            }
        }

 

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 程序猿惹谁了 设计师: 上身试试
应支付0元
点击重新获取
扫码支付

支付成功即可阅读