i making wpf application same work of ssis, in next step want mapp source column database table columns. want achieve
can me find way bind combobox datagrid. working mvvm design pattern.
you can see combobox
when click mouse @ datagridcomboboxcolumn
. let's see example:
model:
public class person { public int idperson { get; set; } public string name { get; set; } } public class team { public int idteam { get; set; } public string nameteam { get; set; } }
viewmodel:
public class mainwindowvm { public mainwindowvm() { loaddata(); } private void loaddata() { persons = new observablecollection<person>() { new person() { idperson = 1, name = "billy" }, new person() { idperson = 2, name = "bobby" }, new person() { idperson = 2, name = "bond" } }; teams = new observablecollection<team>() { new team() { idteam = 1, nameteam = "team a" }, new team() { idteam = 2, nameteam = "team b" }, new team() { idteam = 3, nameteam = "team c" } }; } public observablecollection<person> persons { get; set; } public observablecollection<team> teams { get; set; } }
}
view:
<window x:class="wpfapplication.mainwindow" ...the code omitted brevity xmlns:vm="clr-namespace:wpfapplication.viewmodel" title="a" height="350" width="525" windowstartuplocation="centerscreen"> <window.datacontext> <vm:mainwindowvm/> </window.datacontext> <grid> <stackpanel> <datagrid autogeneratecolumns="false" itemssource="{binding persons}" > <datagrid.columns> <datagridtextcolumn binding="{binding name}" /> <datagridcomboboxcolumn header="courttype" displaymemberpath="nameteam" selectedvaluebinding="{binding idteam}" selectedvaluepath="{binding idteam}" > <datagridcomboboxcolumn.elementstyle> <style targettype="combobox"> <setter property="itemssource" value="{binding relativesource={relativesource findancestor, ancestortype={x:type window}}, path=datacontext.teams}"/> <setter property="isreadonly" value="true"/> </style> </datagridcomboboxcolumn.elementstyle> <datagridcomboboxcolumn.editingelementstyle> <style targettype="combobox"> <setter property="itemssource" value="{binding relativesource={relativesource findancestor, ancestortype={x:type window}}, path=datacontext.teams}"/> </style> </datagridcomboboxcolumn.editingelementstyle> </datagridcomboboxcolumn> <datagridtextcolumn binding="{binding name}"/> </datagrid.columns> </datagrid> </stackpanel> </grid> </window>
Comments
Post a Comment