c# - One datagrid per row of ItemsSource binding -


currently have single datagrid defined in xaml file binds (itemsource) collection of data (called view) , displays in 1 big table (as expected , working perfectly).

however need create datagrid per row, ending many datagrids containing single row of data.

the thing can think of is:
- dynamically create datagrids in-code (somehow) , remove xaml
- populate itemsource of each of these dynamically created datagrids specific row of data, example (pseudo-code):

for each row of view
create new datagrid
assign row itemsource binding

does have better suggestions? can done way proposing it? there better/simpler way?

the reason - customer wants print each row on seperate page create many datagrids , pass each 1 printvisual independantly achieve this.

code:

// datasource, want show 1 recipe per printed page (so per datagrid) list<viewrecipe> view 

xaml:

<datagrid itemssource="{binding view}"           autogeneratecolumns="false"           height="auto"           canuseraddrows="false"           canuserdeleterows="false"           canuserresizecolumns="false"           canuserresizerows="false"           canuserreordercolumns="false"           isreadonly="true"           gridlinesvisibility="none">   <datagrid.columnheaderstyle>     <style targettype="{x:type datagridcolumnheader}">       <setter property="fontweight"               value="bold" />       <setter property="fontsize"               value="12" />     </style>   </datagrid.columnheaderstyle>   <datagrid.columns>     <datagridtextcolumn header="type"                         width="200"                         fontsize="12"                         binding="{binding path=name}" />     <datagridtemplatecolumn header="ingredients"                             width="*">       <datagridtemplatecolumn.celltemplate>         <datatemplate>           <datagrid autogeneratecolumns="false"                     canuseraddrows="false"                     canuserdeleterows="false"                     canuserresizecolumns="false"                     canuserresizerows="false"                     canuserreordercolumns="false"                     isreadonly="true"                     gridlinesvisibility="none"                     itemssource="{binding ingredients}">             <datagrid.columnheaderstyle>               <style targettype="{x:type datagridcolumnheader}">                 <setter property="fontweight"                         value="bold" />                 <setter property="fontsize"                         value="12" />               </style>             </datagrid.columnheaderstyle>             <datagrid.columns>               <datagridtextcolumn header="ingredients"                                   width="*"                                   fontsize="12"                                   binding="{binding path=ingredientname}" />               <datagridtextcolumn header="quantite"                                   width="*"                                   fontsize="12"                                   binding="{binding path=qty}" />             </datagrid.columns>           </datagrid>         </datatemplate>       </datagridtemplatecolumn.celltemplate>     </datagridtemplatecolumn>   </datagrid.columns> </datagrid> 

you can form list of list of viewrecipe , pass itemssource itemscontrol, itemstemplate datagrid.

code:

list<list<viewrecipe>> viewextended = new list<list<viewrecipe>>();  foreach (var r in view) {     var l = new list<viewrecipe>();     viewextended.add(l); } 

xaml

<itemscontrol itemssource="{binding path=viewextended}"> <itemscontrol.itemtemplate>     <datatemplate>     <datagrid itemssource="{binding}">      ......      </datagrid>     </datatemplate <itemscontrol.itemtemplate> </itemscontrol> 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -