I have a requirement to search something on list from current selected item in multilevel treeview. I have 4 Levels in my tree view and searching nodes on 4th level which match some condition.Look at below image:
Now in this image i am searching Red Block which having 1 inside it(Failed one). Below is my code to search:
foreach (var Project in Projects)
{
foreach (var Devices in Project.TestRuns)
{
foreach (var Category in Devices.TestModuleCategories)
{
foreach (var TestModule in Category.TestModules)
{
foreach (var statement in TestModule.TestModuleStatementList)
{
if (statement.TestsFailed == 1 && !statement.IsSearched)
{
TestModule.TestModuleStatementList.ForEach(f => { f.IsCurrentFocused = false; });
statement.IsCurrentFocused = true;
statement.IsSearched = true;
TreeViewItem item = GetTreeViewItem(ViewTestDataTree, statement);
item.IsExpanded = true;
//ViewTestData.SetSelectedItem(ref ViewTestDataTree, item);
//item.Focus();
return;
}
statement.IsCurrentFocused = false;
}
}
}
}
}
Projects.ForEach(a => a.TestRuns.ForEach(b => b.TestModuleCategories.ForEach(c => c.TestModules.ForEach(d => d.TestModuleStatementList.ForEach(f => { f.IsSearched = false; })))));
Now problem is this i am running foreach loop everytime when searching but i want that if user is middle of list anywhere then search should start from there to last of the list and also remaining list from top. Is there any mechanism to start anywhere from a collection and search all nodes from down to up?