0
的ITs XAML代碼爲DataGrid的無法轉換爲DataRowView的WPF中
<DataGrid AutoGenerateColumns="True" HorizontalAlignment="Left" Margin="10,30,0,0" ItemsSource="{Binding}" VerticalAlignment="Top" Height="149" Width="356" Name="orderGrid" SelectionMode="Single" SelectionUnit="FullRow" SelectionChanged="orderGrid_SelectionChanged" />
這裏是我的查詢和項目來源
var orders = (from ss in db.electronics_orders
select new { ss.id,Date = ss.orderdate,Product_Title=ss.Electronic.Name, Quantity = ss.qty, TPrice = ss.qty * ss.unitprice}).ToList();
orderGrid.ItemsSource = orders;
我現在想投選擇項目DataRowView的
try
{
DataRowView grid = (DataRowView)orderGrid.CurrentItem;
}
catch (Exception e1) {
MessageBox.Show(e1.Message);
}
但它顯示錯誤
無法轉換 類型的對象 '<> f__AnonymousType0
5[System.Int32,System.Nullable
1的System.DateTime],System.String,System.Nullable1[System.Int32],System.Nullable
1 [System.Int32]]' 爲類型 '的System.Data.DataRow'。