c# - How to Add rows to DataGrid containing a combox column -


i have datagrid defined follows:

<datagrid autogeneratecolumns="false" height="200" horizontalalignment="left" margin="44,39,0,0" name="datagrid1" verticalalignment="top" width="277">             <datagrid.columns>                 <datagridtextcolumn header="id" />                 <datagridcomboboxcolumn header="value" />             </datagrid.columns>         </datagrid> 

how can bind list of strings datagrid , include items "yes", "no", "maybe" datagridcomboboxcolumn each row?

var fruit new list<string> {"apple","orange","banana"}; 

public class fruit {     public string id {get;set;}     public string name { get; set; }  } 

xaml

  <datagrid autogeneratecolumns="false" name="mygrid" margin="10">         <datagrid.columns>             <datagridtextcolumn binding="{binding path=name}"></datagridtextcolumn>                             <datagridcomboboxcolumn width="100" x:name="result" selectedvaluebinding="{binding result, mode=twoway}" displaymemberpath="{binding result}"></datagridcomboboxcolumn>         </datagrid.columns>     </datagrid> 

code-behind

public partial class datagridcombobox : window {     public list<fruits> fruits { get; set; }     public list<string> result{ get; set; }      public datagridcombobox()     {         fruits  = new list<employee>()         {             new employee() { name = "apple", result= "yes" },             new employee() { name = "mango",result = "no" },             new employee() { name = "banana",result ="maybe" }         };          result= new list<string>();         result.add("yes");         result.add("no");         result.add("maybe");         initializecomponent();         mygrid.itemssource = fruits;         result.itemssource = result;     }   } 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -