1
TreeNode tnKey = 
    treeViewFilters
    .Nodes
    .Cast<TreeNode>()
    .Where(r => r.Text == FilterName)
    .ToArray()[0];

The above code is not working. It reports an error

Error   1   Instance argument: cannot convert from 'System.Windows.Forms.TreeNodeCollection' to 'System.Data.EnumerableRowCollection'   

Error   2   'System.Windows.Forms.TreeNodeCollection' does not contain a definition for 'Cast' and the best extension method overload 'System.Data.EnumerableRowCollectionExtensions.Cast<TResult>(System.Data.EnumerableRowCollection)' has some invalid arguments 

I have taken code from Is there a method for searching for TreeNode.Text field in TreeView.Nodes collection? Any ideas?

Community
  • 1
  • 1
Nest
  • 341
  • 4
  • 23
  • This works fine in linqpad for me (replacing `treeViewFilters` with `new TreeView()`) and `ToArray()[0]` with `FirstOrDefault()`. – DaveShaw Jul 26 '13 at 14:12

1 Answers1

1

Sorry my mistake, i forget to add 'system.linq' name space

Nest
  • 341
  • 4
  • 23