c# - Datagrid binding with LINQ results? WPF -


i trying bind(no code behind =)) datagridview example wpf application results of linq. must pretty easy missing "somehow" somewhere. things must consider: first of using oracle db , have made mappings, having result:

     this.searchcommand = new relaycommand(this.displaymessage, candisplaymessage);     }       public bool candisplaymessage()     {         return true;     }      public void displaymessage()     {        using ( entities ctx = new entities())         {             var query = e in ctx.employees select new { e.employee_id,e.first_name,                          e.last_name, e.email, e.phone_number,                          e.salary, e.department_id};           var results = query.tolist();         }     } 

http://s27.postimg.org/ya0crw701/linqresults.jpg

i know have bind datagrid itemssource, have have made it. used observablecollection bind results datareader (with normal sql commands...) datagrid. xaml looks this:

   <datagrid grid.row="1" grid.columnspan="3" itemssource="{binding}" >         <datagrid.columns>         <datagridtextcolumn header="employee id"    binding="{binding path= employee_id}"/>          <datagridtextcolumn header="first name"     binding="{binding path= first_name}"/>         <datagridtextcolumn header="last name"      binding="{binding path= last_number}"  />         <datagridtextcolumn header="email"          binding="{binding path= email}"  />         <datagridtextcolumn header="phone number"   binding="{binding path= phone_number}"/>         <datagridtextcolumn header="salary"         binding="{binding path= salary}"  />         <datagridtextcolumn header="department id"  binding="{binding path= department_id}"  />         </datagrid.columns>     </datagrid> 

http://s29.postimg.org/or9jhxuau/xaml.jpg

i have tried bind results linq:

  public void displaymessage()     {        using ( entities ctx = new entities())         {             var query = e in ctx.employees select new { e.employee_id,e.first_name,                          e.last_name, e.email, e.phone_number,                          e.salary, e.department_id};           var results = query.tolist();          }     } 

with datagrid nothing coming back! have tried bind observerable collection result having error. missing here? have write on itemssource of datagrid can bind the datagrid results?

thanks in advance!

where populate gridview? maybe work ...

public void displaymessage() {    using ( entities ctx = new entities())     {         var query = e in ctx.employees select new {  e.employee_id,e.first_name,                      e.last_name, e.email, e.phone_number,                      e.salary, e.department_id};       var results = query.tolist();      gridview.datasource = results;      gridview.databind();     } } 

you have set id here

<datagrid grid.row="1" grid.columnspan="3" id="gridview" itemssource="{binding}" > 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -