Skip to main content

I have a wpf datagrid that and am trying to cast a datagrid.SelectedItem to a custom object. Getting the error "Unable to cast object of type 'System.Data.DataRowView' to type 'CarrierRecord'." when this line "set carrierRecord to DG_CellCarriers::SelectedItem as type CarrierRecord" is executed. Works just fine in c#.  Am I missing something basic here? My datagrid is bound to a datatable.

I have a wpf datagrid that and am trying to cast a datagrid.SelectedItem to a custom object. Getting the error "Unable to cast object of type 'System.Data.DataRowView' to type 'CarrierRecord'." when this line "set carrierRecord to DG_CellCarriers::SelectedItem as type CarrierRecord" is executed. Works just fine in c#.  Am I missing something basic here? My datagrid is bound to a datatable.

The actual object that is bound to the dataGrid is a DataRowView. I can get at the selected data using something like the following using the Row property where ItemArray contains the columns in the row:

method-id dataGrid1_SelectionChanged.
procedure division using by value sender as object e as type System.Windows.Controls.SelectionChangedEventArgs.
declare selectedrow as type System.Data.DataRowView = self::dataGrid1::SelectedItem as type System.Data.DataRowView
declare mystring as string = selectedrow::Row::ItemArray[1]

end method.

I have a wpf datagrid that and am trying to cast a datagrid.SelectedItem to a custom object. Getting the error "Unable to cast object of type 'System.Data.DataRowView' to type 'CarrierRecord'." when this line "set carrierRecord to DG_CellCarriers::SelectedItem as type CarrierRecord" is executed. Works just fine in c#.  Am I missing something basic here? My datagrid is bound to a datatable.

This can be the solution to get an item of the DataGrid ItemsSource:
set carrierRecord to DG_CellCarriers::Items::CurrentItem as type CarrierRecord:

Consider, a new row is not of type CarrierRecord (CanUserAddRows="True")

Following 2 statements select same object in my program::
set GridZeile to DGWerte::Items::CurrentItem as type WPFApplDataGrid.GridZeile:
set GridZeile to DGWerte::SelectedItem as type WPFApplDataGrid.GridZeile: