c# - How to Bind Different Lists to DataGridComboBoxColumn in each row using MVVM -


i want bind 'units' property of resultmodel class datagridcomboboxcolumn. other bindings work fine cannot resolve 'units' property. recommends me 'results' list instead of 'units'. want use different lists in each row.

you can see view, viewmodel , model classes below.

view.xaml

<datagrid x:name="datagrid" autogeneratecolumns="false" grid.row="1" itemssource="{binding results}">             <datagrid.columns>                 <datagridtextcolumn header="#" width="20" binding="{binding path=count}" />                 <datagridtextcolumn header="name" width="*" binding="{binding path=componentname}" />                 <datagridtextcolumn header="variable" width="*" binding="{binding path=property}" />                 <datagridtextcolumn header="value" width="*" binding="{binding path=propertyvalue}" />                 <datagridcomboboxcolumn header="unit" width="*" itemssource="{binding units}"/>             </datagrid.columns> </datagrid> 

viewmodel.cs

private list<resultmodel> _results;  public list<resultmodel> results         {             { return _results; }             set             {                 _results = value;                 raisepropertychanged("results");             }         } 

resultmodel.cs

private int _count;         public int count         {             { return _count; }              set { _count = value; raisepropertychanged("count"); }         }          private string _componentname;         public string componentname         {             { return _componentname; }              set { _componentname = value; raisepropertychanged("componentname"); }         }          private string _property;         public string property         {             { return _property; }              set { _property = value; raisepropertychanged("property"); }         }          private double _propertyvalue;         public double propertyvalue         {             { return _propertyvalue; }              set { _propertyvalue = value; raisepropertychanged("propertyvalue"); }         }          private list<object> _units;         public list<object> units         {             { return _units; }              set { _units = value; raisepropertychanged("units"); }         }          private type _componenttype;         public type componenttype         {             { return _componenttype; }              set { _componenttype = value; raisepropertychanged("componenttype"); }         } 

i had use datagridtemplatecolumn contained combobox work properly. assumes object in units has name property display, should adjust displaymemberpath accordingly. pribably want bind selecteditem something, know item picked.

<datagridtemplatecolumn header="unit">     <datagridtemplatecolumn.celltemplate>         <datatemplate datatype="local:resultmodel">             <combobox                 displaymemberpath="name"                 itemssource="{binding path=units}" />         </datatemplate>     </datagridtemplatecolumn.celltemplate> </datagridtemplatecolumn> 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -