1

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

Andrea Antonangeli
  • 1,242
  • 1
  • 21
  • 32
3wic
  • 500
  • 6
  • 22
  • 2
    The `DataRowView` has a property [`Row`](http://msdn.microsoft.com/en-us/library/system.data.datarowview.row.aspx) ;-) – Tim Schmelter Jun 13 '13 at 14:10

1 Answers1

6
DataRow row = ((DataRowView)SelectedZone).Row;
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964