【问题标题】:A way to get a DataRow from a DataRowView一种从 DataRowView 获取 DataRow 的方法
【发布时间】:2013-06-09 23:04:18
【问题描述】:

我目前正在尝试获取 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
        }



    }

感谢您的帮助

【问题讨论】:

  • DataRowView 有一个属性Row ;-)

标签: c# wpf xaml datagrid datarowview


【解决方案1】:
DataRow row = ((DataRowView)SelectedZone).Row;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-21
    • 1970-01-01
    • 2010-12-21
    • 2023-04-07
    相关资源
    最近更新 更多