C# WPF Bind a specific object of a list to a GridViewColumn

308 Views Asked by At

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

1

There are 1 best solutions below

2
Kevin Cook On BEST ANSWER
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