I found this C# answer on S.O., but can't seem to get this working: c# populate treeview from LINQ object
In my case, suppose I have a List(Of Report_Data) which, for example, looks like this:
Var1 Var2
V1 Sub Item 1
V1 Sub Item 2
V1 Sub Item 3
V2 Sub Item 1
V2 Sub Item 2
V3 Sub Item 1
And I'm looking to use LINQ to fill a treeview to look like:
V1 (CheckBox)
-------Sub Item 1 (CheckBox)
-------Sub Item 2 (CheckBox)
-------Sub Item 3 (CheckBox)
V2 (CheckBox)
-------Sub Item 1 (CheckBox)
-------Sub Item 2 (CheckBox)
V3 (CheckBox)
-------Sub Item 1 (CheckBox)
So, in my Treeview-filling routine, I create the following in-memory query:
Dim GroupedReports = From Rpt As Report_Data In ReportsToBeProcessed
Group Rpt By Rpt.Var1 Into Group
And then I thought I could loop through the Groups and then the grouped objects to fill the treeview - something along the lines of:
For Each Grp As Object In GroupedReports
... Add Parent node ...
For Each Rpt As Report_Data In Grp
... Add Child Node ...
Next
Next
Firstly, I don't know what data-type to use for my Grp variable and secondly it doesn't seem to be working...
How do I do this correctly?