问题
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