c# - how to update other columns after select from DataGridComboBoxColumn when the row is still editing? -
i searching solution quite time without luck , hope can expert here.
for example, have product class:
public class productmodel : observableobject { private int id; public int id { { return id; } set { id = value; onpropertychanged("id"); } } private string name; public string name { { return name; } set { name = value; onpropertychanged("name"); } } private decimal unitprice; public decimal unitprice { { return unitprice; } set { unitprice = value; onpropertychanged("unitprice"); } } }
and have class called order:
public class order : observableobject { sportsentities db; private int id; public int id { { return id; } set { id = value; onpropertychanged("id"); } } private int productid; public int productid { { return productid; } set { productid = value; unitprice = db.products.first(x => x.id == value).unitprice; onpropertychanged("productid"); onpropertychanged("unitprice"); } } private decimal unitprice; public decimal unitprice { { return unitprice; } set { unitprice = value; onpropertychanged("unitprice"); } } public order() { db = new sportsentities(); } }
in view, have bound observablecollection viewmodel datagrid 2 columns - "product" , "unit price". 'product' column datagridcomboboxcolumn itemssource binding observablecollection.
i can select product , unit price once finish row editing. however, want unit price column updated after select product while still updating row.
can please advise? thank you.
added:
view
<datagrid itemssource="{binding orders}" autogeneratecolumns="false"> <datagrid.columns> <datagridcomboboxcolumn width="120" header="product" selectedvaluebinding=" {binding productid}" displaymemberpath="name" selectedvaluepath="id"> <datagridcomboboxcolumn.elementstyle> <style targettype="combobox"> <setter property="itemssource" value="{binding datacontext.products, relativesource={relativesource mode=findancestor, ancestortype={x:type window}}}" /> </style> </datagridcomboboxcolumn.elementstyle> <datagridcomboboxcolumn.editingelementstyle> <style targettype="combobox"> <setter property="itemssource" value="{binding datacontext.products, relativesource={relativesource mode=findancestor, ancestortype={x:type window}}}" /> </style> </datagridcomboboxcolumn.editingelementstyle> </datagridcomboboxcolumn> <datagridtextcolumn width="80" header="unit price" binding="{binding unitprice}" /> </datagrid.columns> </datagrid>
viewmodel
public class mainviewmodel : viewmodelbase { private sportsentities db; private observablecollection<productmodel> products; public observablecollection<productmodel> products { { return products; } set { products = value; onpropertychanged("products"); } } private observablecollection<order> orders; public observablecollection<order> orders { { return orders; } set { orders = value; onpropertychanged("orders"); } } public mainviewmodel() { initialized(); } private void initialized() { db = new sportsentities(); products = new observablecollection<productmodel>(); foreach (product p in db.products) { products.add(new productmodel { id = p.id, name = p.name, unitprice = p.unitprice }); } orders = new observablecollection<order>(); } }
Comments
Post a Comment