I'm having trouble editing fields/properties in a hierarchical list with the help of a second lookup list. Everything I try looks like a mess and is hard to maintain. Are binary search trees my friend? How would I apply them? Flattening my hierarchical structure doesn't work as I need the hierarchy, just filtered.
public class Filter
{
public string Name {get;set;}
public bool IsActive {get;set;}
public bool IsDisplayed {get;set;}
public string List<Filter> Filters {get;set}
}
public List<string> ActiveFilters {"Green", "LighterYellow", "Red", "Meep")};
My base filters basically look like this:
- Colors
- Green
- Yellow
- LightYellow
- LighterYellow
- LightYellow
- OrangishYellow
- Red
- DarkRed
- Sounds
- Meep
- Moop
- Maap
Now I'm trying to set some of these filters to active. But of course the parents of children who are in the ActiveFilters
need to be displayed (IsDisplayed
) otherwise you wouldn't be able to see the child items.
In the end I want the hierarchy to look like this (based on applying the ActiveFilters
, bold indicates IsActive
, italic IsDisplayed
):
- Colors
- Green
- Yellow
- LightYellow
- LighterYellow
- LightYellow
- Red
- Sounds
- Meep
I have been trying to recursively loop through the hierarchical list, but I don't know how to set the parents to IsDisplayed
(as I would have to "go back up"). When looping the other way through the ActiveFilters
I don't want to iterate over the whole filter list for each active filter performance wise.