A way to get a DataRow from a DataRowView

筅森魡賤 提交于 2019-12-11 10:39:25

问题


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

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

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
        }



    }

Thanks for your help


回答1:


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


来源:https://stackoverflow.com/questions/17089147/a-way-to-get-a-datarow-from-a-datarowview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!