WPF Combobox is blank (data binding) -


i followed simple tutorial comboboxes (http://www.wpf-tutorial.com/list-controls/combobox-control/). here xaml combobox :

<combobox name="coursesteach" grid.row="7" grid.column="1"  width="150" height="auto" margin="0,24">                 <combobox.itemtemplate>                     <datatemplate>                         <stackpanel orientation="horizontal">                             <textblock text="{binding name}" foreground="black" />                         </stackpanel>                     </datatemplate>                 </combobox.itemtemplate>             </combobox> 

code behind :

public addtrainer()         {             initializecomponent();              using (model1container context = new model1container())             {                  foreach (var row in context.courseset)                 {                     if (row.discipline != null)                     {                                              coursesteach.itemssource = row.discipline;                                            }                     metrocustombox.showok(row.discipline); // can see right values                      }              }         } 

but results not in combobox, although can can print them. lot responses.

to add items in combobox code behind may use items property. previous code :

foreach (var row in context.courseset) {      if (row.discipline != null)      {                               coursesteach.items.add(row.discipline);                             }    } 

but better way, use itemssource property, binding, or set list. previous code :

coursesteach.itemssource = context.courseset.where(row => row.dicipline != null).select(row => row.dicipline).tolist(); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -