c# - How to display a ComboBox in a DataGrid if the DataTable it is bound to has a list of items? -


i have dataset. don't know contents of set. have display table of set in datagrid. i'm able using following code. able work it, have created own dataset. customerdataprovider class have created has method returns dummy dataset.

customerdataprovider provider = new customerdataprovider(); dataset ds = new dataset(); datatable table = new datatable(); dataview view = new dataview();        public mainwindow()     {         initializecomponent();         ds = dataset.getdataset();         table = ds.tables[0];         view = table.asdataview();         this.datacontext = view;     }   <grid>     <datagrid x:name="dynamicgrid" itemssource="{binding path=., mode=twoway}" columnwidth="*"  /> </grid> 

now, if datatable contains bool value, datagrid automatically displays checkbox. want able automatically display combobox if datatable contains list of items. how go achieving this?

instead of auto-generating columns, set autogeneratecolumns false, can define columns , bind different fields of datatable. can take datagridtemplatecolumn , provide celltemplate same. see reference code below:

  <datagrid autogeneratecolumns="false">     <datagridtemplatecolumn>       <datagridtemplatecolumn.celltemplate>         <datatemplate>           <combobox />         </datatemplate>       </datagridtemplatecolumn.celltemplate>     </datagridtemplatecolumn>   </datagrid> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -