I’ve got a DataGrid that I’ve setup a doubleclick eventsetter that calls a method. Below is my xaml, following that is my codebehind page. The double click event works, but the return I get is “system.data.datarowview” and I don’t know why. I’m trying to get the “vehicleID” value of the row which is its own column that is hidden.
XAML:
<DataGrid Name="OpenVehicles" AutoGenerateColumns="False" IsReadOnly="False" SelectedItem="{Binding vehicleID}" SelectionUnit="FullRow">
<DataGrid.ItemContainerStyle>
<Style TargetType="DataGridRow">
<EventSetter Event="MouseDoubleClick" Handler="OpenVehicleClick" />
</Style>
</DataGrid.ItemContainerStyle>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding vehicleID}" Width="*" Header="vehicleID" Visibility="Hidden"/>
<DataGridTextColumn Binding="{Binding date, StringFormat=\{0:MMM dd yyyy \}}" Width="*" Header="Date"/>
<DataGridTextColumn Binding="{Binding companyshortname}" Width="*" Header="Customer"/>
<DataGridTextColumn Binding="{Binding subject}" Width="5*" Header="Vehicle Description"/>
<DataGridTextColumn Binding="{Binding FName}" Width="*" Header="Owner"/>
</DataGrid.Columns>
C# Code:
private void OpenVehicleClick(object sender, RoutedEventArgs e)
{
MessageBox.Show(OpenVehicles.CurrentCell.Item.ToString());
}
Any ideas on how to retrieve the column value or any other suggestions are more than welcome. I’m beyond stumped.
The
DataRowView.Rowproperty will contain theDataRowthat you want. From there you can access the column value usingDataRowView.Row["ColumnName"]indexer