wpf - Add rows of comboboxes to datagrid -


i'm trying create datagrid have 1 row column headers, , 10 more rows, filled comboboxes each column. instance:

    <datagrid autogeneratecolumns="false"                       name="datagrid1">         <datagrid.columns>             <datagridcomboboxcolumn header="products"      selectedvaluebinding="{binding productname}">     <datagridcomboboxcolumn.elementstyle>         <style targettype="combobox">             <setter property="itemssource" value="{binding path=productnameslist,                  relativesource={relativesource ancestortype={x:type window}}}"/>         </style>     </datagridcomboboxcolumn.elementstyle>     <datagridcomboboxcolumn.editingelementstyle>         <style targettype="combobox">             <setter property="itemssource" value="{binding path=productnameslist,                 relativesource={relativesource ancestortype={x:type window}}}"/>         </style>     </datagridcomboboxcolumn.editingelementstyle> </datagridcomboboxcolumn>              <datagridcomboboxcolumn header="amount" />              <datagridcomboboxcolumn header="units" />         </datagrid.columns>     </datagrid> 

now, need 10 rows of 3 comboboxes. i've tried google it, google-fu failing me, i've found tells me bind rows list. want possible? or should find way?

edit 1

what i'd meant ask, once have this, how can populate 10 rows of 3 comboboxes? each column have same items in box.

edit 2

i edited show i've added jim's code. however, if create productnameslist, , fill 10 items, , bind column, 10 rows of empty boxes.

edit 3

here's list<string>:

        var productnameslist = new list<string>();         var test1 = "test1";         var test2 = "test2";         var test3 = "test3";         var test4 = "test4";         var test5 = "test5";         var test6 = "test6";         var test7 = "test7";         var test8 = "test8";         var test9 = "test9";         var test10 = "test10";          productnameslist.add(test1);         productnameslist.add(test2);         productnameslist.add(test3);         productnameslist.add(test4);         productnameslist.add(test5);         productnameslist.add(test6);         productnameslist.add(test7);         productnameslist.add(test8);         productnameslist.add(test9);         productnameslist.add(test10);          grid1.itemssource = productnameslist; 

simply bind combobox column's element , editing styles list. example binds list in window.cs file.

public partial class mainwindow : window {     public list<string> productnameslist { get; set; }     public mainwindow()     {         initializecomponent();          productnameslist = new list<string>();          productnameslist.add("hamburger");         productnameslist.add("uranium");         productnameslist.add("toothbrush");     } }  <datagridcomboboxcolumn header="products"      selectedvaluebinding="{binding productname}">     <datagridcomboboxcolumn.elementstyle>         <style targettype="combobox">             <setter property="itemssource" value="{binding path=productnameslist,                  relativesource={relativesource ancestortype={x:type window}}}"/>         </style>     </datagridcomboboxcolumn.elementstyle>     <datagridcomboboxcolumn.editingelementstyle>         <style targettype="combobox">             <setter property="itemssource" value="{binding path=productnameslist,                 relativesource={relativesource ancestortype={x:type window}}}"/>         </style>     </datagridcomboboxcolumn.editingelementstyle> </datagridcomboboxcolumn> 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -