Search code examples
c#wpfentity-frameworkentitydesktop-application

How to show ICollection as one String in GridController in c#, wpf


I have an object "User" which contains ICollection "Phone". I want to display them on TableView-GridController of DevExpress in one column as given below:

<dxg:GridColumn VisibleIndex="2"
        FieldName="User.Phone"
        IsSmart="True"
        ReadOnly="True"
        MinWidth="120"
        Header="Phone" />

I tried to make a new variable in my entity that carries all this Phone in one string as given below:

[NotMapped]
public string AllPhones
{
   get
   {
      string allPhones = "";
      if (Phone != null) 
      {
         foreach (var p in Phone)
         {
            allPhones += p.Lable + "\n";
         }
      }              
            return allPhones;
   }
}

Converted FieldName="User.Phone" to FieldName="User.AllPhones" But it's not working.

There is another way to solve this problem like to show Phones in DropDownList or show the first one.

Below is the data how I put in the GridController

var qry = SharedBll.Db.Patient.Take(100);
ContactGridControl.ItemsSource = qry.ToList();

Solution

  • [NotMapped]
    public string AllPhones
    {
       get
       {
          string allPhones = "";
          foreach (var p in Phone)
          {
             allPhones += p.Lable + "\n";
          }            
          return allPhones;
       }
    }