Domanda

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

È stato utile?

Soluzione

DataRow row = ((DataRowView)SelectedZone).Row;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top