从DataRowView获取DataRow的方法 [英] A way to get a DataRow from a DataRowView

查看:985
本文介绍了从DataRowView获取DataRow的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试获取DataGrid中选定行的内容.

I'm currently trying to get the content of a selected row in a DataGrid.

问题是我实际上得到了DataRowView,但是我却无能为力...

The problem is that I actually get a DataRowView but I can't do anything with it...

我想访问我的DataGrid中所选行的所有字段.

I would like to acces to all the field of my selected row in my DataGrid.

以下代码可为您提供帮助:

Here's the code to help you :

XAML:

<DataGrid  SelectionUnit="FullRow" SelectedItem="{Binding SelectedZone, Mode=TwoWay}" AutoGenerateColumns="True" Margin="0,167,6,24" Name="existingCase"  Width="780" >
        <DataGrid.RowStyle>
            <Style TargetType="{x:Type DataGridRow}">
                <EventSetter Event="MouseDoubleClick" Handler="resultDataGrid_MouseDoubleClick"/>
            </Style>
        </DataGrid.RowStyle>
    </DataGrid>

cs:

 private void resultDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        if (sender != null)
        {
            SelectedZone = existingCase.SelectedItem; 

            // SelectedZone is declared as private object SelectedZone


            MessageBox.Show(SelectedZone.GetType().ToString()); 

            // Result to a System.Data.DataRowView
        }



    }

感谢您的帮助

推荐答案

DataRow row = ((DataRowView)SelectedZone).Row;

这篇关于从DataRowView获取DataRow的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆