2

I have a list of "StepModel" that follow the below Structure: (this List gets added to a Treeview Control)

public class StepModel { 
// Other Properties removed for brevity
  public string SequenceNumber {get;set;} //1, 1.1, 2, 2.1 and so on
  public string parentSequenceNumber{get;set;} //for example, for sequence number 1.1, its parent would be 1
  public List<StepModel> ChildSteps {get;set;}
}

Each StepModel within this List has a String (SequenceNumber) as below (a List of Steps): This is a List Retrieved from API/Database in order of Sequence Number (1, 1.1, 1.1.1 etc)

//List[Index] = SequenceNumber (StepModel Class, containing Property Sequence Number)
List[0] = 1  
List[1] = 1.1
List[2] = 1.1.1
List[3] = 2
List[4] = 2.1

Each StepModel within this List has a Sub-List of itself to hold "ChildSteps"

I understand this will be some sort of recursive function but I am having great trouble with figuring this out.

How do i properly expand a Flattened List to place Children within their respective parents? Expanding it to become a Tree basically?

Exxili
  • 45
  • 8
  • Is the list a string you want to parse into `StepModel` objects? – Stefan Oct 03 '19 at 13:51
  • No, the List is a flattened List of Step Models List e.g List[0] = Sequence Number 1 / List[1] = Sequence Number 1.1 and so on, The data is retrieved from a Database – Exxili Oct 03 '19 at 14:01

0 Answers0