I have a WPF window with some textboxes, comboboxes and a grid using MVVM
the comboboxes and grid are bound to DataTable and DataViews, only the selectedItem values are bound to the Model
As of now, using helper methods as follows
void GetSelected()
{
if ( SelectedDataRowView != null )
obj.prop1 = (int)(SelectedDataRowView.Row["field1"]);
else
obj.prop1 = defaultValue1;
if ( SelectedDataRow1 != null )
obj.prop2 = (double)(SelectedDataRow["field2"]);
if ( SelectedDataRow2!= null )
obj.prop3 = (string)(SelectedDataRow2["field3"]);
...
}
/// and
void ToSelected()
{
if ( TryFindDataRow("field1", obj.prop1, dv1, out drv1 )
SelectedDataRowView = drv1;
else
SelectedDataRowView = null ;
...
}
as you can see, its pretty ugly, wondering how to clean it up !!
FYI can,t use EF & get rid of DataTable/DataView for now – the db is non sql server
Maybe you can convert your DataTable / DataRows to POCO objects with proper interfaces and put them in ObservableCollection which are more MVVM friendly. You can write mappers to achieve this or use frameworks like AutoMapper. You can keep using what you do and just use a mapper layer to convert them back and forth.