c# - WPF Datagrid lookup Combobox -


i have basic mvvm wpf application shows bunch of user related info in datagrid. example have 2 classes (i simplified classes , have not implemented inotifypropertychanged in real application)

public class address {     public string streetname { get; set; } }  public class person {     public string name { get; set; }     public string street { get; set; } } 

my viewmodel contains 2 observablecollections.

observablecollection<person>
observablecollection<address>

i bind viewmodel window , shows persons collection fine. want, address combobox , user can select values address collection above. lookup table.

here xaml code. managed, shows address collection, wont show me actual record person collection inital record.

            <datagridtextcolumn header="name" binding="{binding name}"></datagridtextcolumn>             <datagridtextcolumn header="street" binding="{binding street}"></datagridtextcolumn>              <datagridtemplatecolumn>                 <datagridtemplatecolumn.celltemplate>                     <datatemplate>                         <combobox itemssource="{binding datacontext.addresses, relativesource={relativesource findancestor, ancestortype={x:type local:mainwindow}}}" displaymemberpath="streetname">                         </combobox>                     </datatemplate>                 </datagridtemplatecolumn.celltemplate>             </datagridtemplatecolumn> 

combobox

set selecteditem or selectedvalue property (depending on you're binding to), address. if storing street name you'd have this:

<datatemplate>     <combobox itemssource="..."               displaymemberpath="streetname"               selectedvaluepath="streetname"               selectedvalue="{binding street}"/> </datatemplate> 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -