c# - Getting lookup value from Id inside the binding of DataGrid -


i have situation in below classes explain

public class userdetail {     public string usercode{get; set;}     public uint roleid{get; set;}     public uint groupid{get; set;} } 

and classes

public class userroledetail {     public uint roleid{get; set;}     public string rolename{get; set;} } 

i have data grid , bound datacontext collection of userdetail objects.

            <datagrid x:name="usersgrid"                       alternatingrowbackground="lightblue"                       canuseraddrows="false"                       canuserdeleterows="false"                       canuserreordercolumns="true"                       itemssource="{binding}"                       canuserresizecolumns="true"                       autogeneratecolumns="false">                 <datagrid.columns>                     <datagridtextcolumn header="user code"                                         binding="{binding path=usercode}"/>                     <datagridtextcolumn header="role"                                         binding="{binding path=roleid}">                         <!-- need rolename looking roledetails collection-->                     </datagridtextcolumn>                     <datagridtextcolumn header="group"                                         binding="{binding path=groupid}"/>                 </datagrid.columns>             </datagrid> 

the output showing integer roleid field in userdetail class. want show rolename looking roleid in roledetails collection in code behind.

is there way can achieve in xaml itself. light on using converters??

thanks in advance.

my suggestion here create wrapper class lets userdetailwrapper contain userdetailinstance , userroledetailinstance

    public class userdetailwrapper     {         public userdetail userdetail         {             get;             set;         }          public userroledetail userroledetail { get; set; }     } 

in code behind generate list of userdetailwrapper userdetail collection , set userroledetail correcponding roleid.

now bind collection itemssource datagrid.

you have update bindings accordingly like

<datagridtextcolumn header="user code"                                         binding="{binding path=userdetail.usercode}"/> 

and userroledetailname can directly do

<datagridtextcolumn header="role"                                         binding="{binding path=userroledetail.rolename}"> 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -