ColonelPanic

Filling a tree with linq group

Apr 13th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. var instancesByPrograms = instances
  2.     .GroupBy(instance => instance.ProgramsDescription)
  3.     .OrderBy(grouped => grouped.Key);
  4.  
  5. foreach (var instanceGroup in instancesByPrograms)
  6. {
  7.     var parentNode = new TreeNode(
  8.         instanceGroup.Key,
  9.         instanceGroup.Select(instance =>
  10.         {
  11.             var node = new TreeNode(instance.Description);
  12.             node.Tag = instance;
  13.             return node;
  14.         }).ToArray());
  15.  
  16.     treeView.Nodes.Add(parentNode);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment