我有一個DataGrid,我已經設置了一個調用方法的doubleclick事件調用程序。下面是我的xaml,接下來是我的代碼隱藏頁面。雙擊事件的作品,但我得到的回報是「system.data.datarowview」,我不知道爲什麼。我試圖獲取隱藏自己列的行的「vehicleID」值。檢索數據綁定行列的值
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#代碼:
private void OpenVehicleClick(object sender, RoutedEventArgs e)
{
MessageBox.Show(OpenVehicles.CurrentCell.Item.ToString());
}
如何檢索列值或其他任何建議,非常歡迎任何想法。我無法抗拒。
這固定它,爲其他人搜索:(c#方法) DataRowView row = OpenVehicles.SelectedItem作爲DataRowView; MessageBox.Show(row.Row [「VehicleID」] .ToString()); – getintanked