The function i've made assumes that the leveling always begin at Level 0 based on the image you've provided.
This function also assumes that after a Level 0 item, any value of level, greater than 0 will be considered as a child node of the previously encountered level 0 item.
What i did here is that, i've created a list of TreeNodes and a list of Levels based on your struct, and will loop through the list based on levels, if a level is detected greater than the initially provided level, a recursive call will be made to process the sub levels.
public List<TreeNode> MainNodes(List<Levels> strut, int level){
List<TreeNode> parentNode = new List<TreeNode>();
for(int x = 0; x< strut.Count; x++){
var data = strut[x];
if(data.Level == level){
TreeNode nodeC = new TreeNode();
nodeC.Name = strut[x].Index.ToString(); //Index value from struct
if(x + 1 < strut.Count){
if(strut[x+1].Level > level){
var newArray = new List<Levels>(strut);
newArray.RemoveAt(x);
nodeC.Nodes.AddRange(MainNodes(newArray, level + 1);
}
}
parentNode.Add(nodeC);
}
}
return parentNode;
}
This functions returns the nodes and sub-nodes based on your requirement.