-1

i'm working on this since a while but didn't solved my problem.

The Case:

I have list A which contains objects of Info. Info has the properties id, name and list B which contains objects of Details. Details has the properties id, Name and a bool.

Is it possible to bind list A to a ListView and show the property of an object from list B where the bool is true?

edit:

List B contains more than one object but only one of the objects has a true bool, the others have false. I want to show the Name of the object with the true bool in the GridViewColumn with Binding but didn't find a way till now

Andy Greb
  • 29
  • 4
  • 1
    this is your question? "**Is it possible to bind list A to a ListView and show the property of an object from list B where the bool is true?**", short answer: yes it is, how it depends on how you want to display them, whether it has one or more, etc. – Celso Lívero Dec 08 '17 at 16:38
  • Sorry for not being precisely, still struggling with english – Andy Greb Dec 08 '17 at 16:50
  • Kevin Cook gave you a good solution, in his solution it will show a comma-separated list of True Details, if you have one or more, it will be displayed in a single line (P.S .: I speak Portuguese (Brazil), English is not my main language, there are many people around here who do not have native English, it's normal.) – Celso Lívero Dec 08 '17 at 17:14

1 Answers1

2
public class Info
{
    public int Id { get; set; }
    public string Name { get; set; }
    List<Detail> Details { get; set; }

    public string GoodDetails
    {
        get { return String.Join(",", Details.Where(x => x.Good == true).Select(y => y.Name)); }
    }
}

public class Detail
{
    public int Id { get; set; }
    public string Name { get; set; }
    public bool Good { get; set; }
}

So taking from your list of Details with the bool (which I called Good) set to true, I make a separate property called GoodDetails which pulls all of the names into a comma delimited string. So you just bind to GoodDetails

Kevin Cook
  • 1,922
  • 1
  • 15
  • 16
  • ok, thanks, that works, but is there also a solution which works for auto generated classes from entity framework? – Andy Greb Dec 08 '17 at 20:16
  • You can create a class that inherits from the auto generated class and adds the property you need. – Kevin Cook Dec 08 '17 at 20:18