c# - 一种从 DataRowView 获取 DataRow 的方法

标签 c# wpf xaml datagrid datarowview

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

问题是我实际上得到了一个 DataRowView 但我不能用它做任何事情......

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

这是可以帮助您的代码:

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;

关于c# - 一种从 DataRowView 获取 DataRow 的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17089147/

相关文章:

c# - 没有浏览器的谷歌驱动 OAuth2

c# - 检查是否安装了VLC

c# - 如何实例化复杂的控件组并访问它们的值? (wpf 与 Visual Studio )

c# - Wpf RichTextBox 换行问题

xaml - 按钮内的 Xamarin.Forms TextBlock。自定义文本换行

c# - 禁用 GridViewColumn 调整大小

c# - 有没有办法从 IComparer 派生 IEqualityComparer?

c# - 是否有类似 Shazzam 和 Soundhood 的歌曲检测库?

c# - 具有多个参数的 WCF Rest GET

c# - 任务的返回类型错误